/** * {@inheritdoc} */ public function collect(Request $request, Response $response, \Exception $exception = NULL) { $activeTheme = $this->themeManager->getActiveTheme(); $this->data['activeTheme'] = ['name' => $activeTheme->getName(), 'path' => $activeTheme->getPath(), 'engine' => $activeTheme->getEngine(), 'owner' => $activeTheme->getOwner(), 'baseThemes' => $activeTheme->getBaseThemes(), 'extension' => $activeTheme->getExtension(), 'styleSheetsRemove' => $activeTheme->getStyleSheetsRemove(), 'libraries' => $activeTheme->getLibraries(), 'regions' => $activeTheme->getRegions()]; if ($this->themeNegotiator instanceof ThemeNegotiatorWrapper) { $this->data['negotiator'] = ['class' => $this->getMethodData($this->themeNegotiator->getNegotiator(), 'determineActiveTheme'), 'id' => $this->themeNegotiator->getNegotiator()->_serviceId]; } }
/** * {@inheritdoc} */ public function evaluate() { if (!$this->configuration['theme']) { return TRUE; } return $this->themeNegotiator->determineActiveTheme($this->routeMatch) == $this->configuration['theme']; }
/** * Tests the building of a full page variant. * * @covers ::build * @covers ::getRegionAssignments */ public function testBuild() { $theme = $this->randomMachineName(); $display_variant = $this->setUpDisplayVariant(); $this->themeNegotiator->expects($this->any())->method('determineActiveTheme')->with($this->routeMatch)->will($this->returnValue($theme)); $display_variant->expects($this->once())->method('getRegionNames')->will($this->returnValue(array('top' => 'Top', 'bottom' => 'Bottom'))); $blocks_config = array('block1' => array(TRUE, 'top', 0), 'block2' => array(FALSE, 'bottom', 0), 'block3' => array(TRUE, 'bottom', 5), 'block4' => array(TRUE, 'bottom', -5)); $blocks = array(); foreach ($blocks_config as $block_id => $block_config) { $block = $this->getMock('Drupal\\block\\BlockInterface'); $block->expects($this->once())->method('access')->will($this->returnValue($block_config[0])); $block->expects($this->any())->method('get')->will($this->returnValueMap(array(array('region', $block_config[1]), array('weight', $block_config[2]), array('status', TRUE)))); $blocks[$block_id] = $block; } $this->blockViewBuilder->expects($this->exactly(3))->method('view')->will($this->returnValue(array())); $this->blockStorage->expects($this->once())->method('loadByProperties')->with(array('theme' => $theme))->will($this->returnValue($blocks)); $expected = array('top' => array('block1' => array(), '#sorted' => TRUE), 'bottom' => array('block4' => array(), 'block3' => array(), '#sorted' => TRUE)); $this->assertSame($expected, $display_variant->build()); }
/** * Page callback: Tests the theme negotiation functionality. * * @param bool $inherited * TRUE when the requested page is intended to inherit * the theme of its parent. * * @return string * A string describing the requested custom theme and actual * theme being used * for the current page request. */ public function themePage($inherited) { $theme_key = $this->themeManager->getActiveTheme()->getName(); // Now we check what the theme negotiator service returns. $active_theme = $this->themeNegotiator->determineActiveTheme($this->routeMatch); $output = "Active theme: {$active_theme}. Actual theme: {$theme_key}."; if ($inherited) { $output .= ' Theme negotiation inheritance is being tested.'; } return ['#markup' => $output]; }
/** * Tests the building of a full page variant. * * @covers ::build * @covers ::getRegionAssignments * * @dataProvider providerBuild */ public function testBuild(array $blocks_config, $visible_block_count, array $expected_render_array) { $theme = $this->randomMachineName(); $display_variant = $this->setUpDisplayVariant(); $this->themeNegotiator->expects($this->any())->method('determineActiveTheme')->with($this->routeMatch)->will($this->returnValue($theme)); $display_variant->expects($this->once())->method('getRegionNames')->will($this->returnValue(array('top' => 'Top', 'center' => 'Center', 'bottom' => 'Bottom'))); $display_variant->setMainContent(['#markup' => 'Hello kittens!']); $blocks = array(); $block_plugin = $this->getMock('Drupal\\Core\\Block\\BlockPluginInterface'); $main_content_block_plugin = $this->getMock('Drupal\\Core\\Block\\MainContentBlockPluginInterface'); foreach ($blocks_config as $block_id => $block_config) { $block = $this->getMock('Drupal\\block\\BlockInterface'); $block->expects($this->once())->method('access')->will($this->returnValue($block_config[0])); $block->expects($this->any())->method('get')->will($this->returnValueMap(array(array('region', $block_config[1]), array('weight', $block_config[2]), array('status', TRUE)))); $block->expects($this->any())->method('getPlugin')->willReturn($block_config[3] ? $main_content_block_plugin : $block_plugin); $blocks[$block_id] = $block; } $this->blockViewBuilder->expects($this->exactly($visible_block_count))->method('view')->will($this->returnValue(array())); $this->blockStorage->expects($this->once())->method('loadByProperties')->with(array('theme' => $theme))->will($this->returnValue($blocks)); $this->assertSame($expected_render_array, $display_variant->build()); }
/** * Initializes the active theme for a given route match. * * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The current route match. */ protected function initTheme(RouteMatchInterface $route_match = NULL) { // Determine the active theme for the theme negotiator service. This includes // the default theme as well as really specific ones like the ajax base theme. if (!$route_match) { $route_match = \Drupal::routeMatch(); } if ($route_match instanceof StackedRouteMatchInterface) { $route_match = $route_match->getMasterRouteMatch(); } $theme = $this->themeNegotiator->determineActiveTheme($route_match); $this->activeTheme = $this->themeInitialization->initTheme($theme); }
/** * Gets the current theme for this page. * * @return string * The current theme. */ protected function getTheme() { return $this->themeNegotiator->determineActiveTheme($this->routeMatch); }