diff --git a/core/modules/system/tests/modules/menu_test/src/Controller/MenuTestController.php b/core/modules/system/tests/modules/menu_test/src/Controller/MenuTestController.php index 6c4f17f..97c80a7 100644 --- a/core/modules/system/tests/modules/menu_test/src/Controller/MenuTestController.php +++ b/core/modules/system/tests/modules/menu_test/src/Controller/MenuTestController.php @@ -7,12 +7,66 @@ namespace Drupal\menu_test\Controller; +use Drupal\Core\Controller\ControllerBase; +use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\Core\Theme\ThemeManagerInterface; +use Drupal\Core\Theme\ThemeNegotiatorInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; + /** * Controller routines for menu_test routes. */ -class MenuTestController { +class MenuTestController extends ControllerBase { + + /** + * The theme manager. + * + * @var \Drupal\Core\Theme\ThemeManagerInterface + */ + protected $themeManager; /** + * The theme negotiator. + * + * @var \Drupal\Core\Theme\ThemeNegotiatorInterface + */ + protected $themeNegotiator; + + /** + * The active route match. + * + * @var \Drupal\Core\Routing\RouteMatchInterface + */ + protected $routeMatch; + + /** + * Constructs the MenuTestController object. + * + * @param \Drupal\menu_test\Controller\ThemeManagerInterface $theme_manager + * The theme manager. + * @param \Drupal\menu_test\Controller\ThemeNegotiatorInterface $theme_negotiator + * The theme negotiator. + * @param \Drupal\menu_test\Controller\RouteMatchInterface $route_match + * The current route match. + */ + public function __construct(ThemeManagerInterface $theme_manager, ThemeNegotiatorInterface $theme_negotiator, RouteMatchInterface $route_match) { + $this->themeManager = $theme_manager; + $this->themeNegotiator = $theme_negotiator; + $this->routeMatch = $route_match; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('theme.manager'), + $container->get('theme.negotiator'), + $container->get('current_route_match') + ); + } + + /** * Some known placeholder content which can be used for testing. * * @return string @@ -52,10 +106,10 @@ public function titleCallback(array $_title_arguments = array(), $_title = '') { * for the current page request. */ public function themePage($inherited) { - $theme_key = \Drupal::theme()->getActiveTheme()->getName(); + $theme_key = $this->themeManager->getActiveTheme()->getName(); // Now we check what the theme negotiator service returns. - $active_theme = \Drupal::service('theme.negotiator') - ->determineActiveTheme(\Drupal::routeMatch()); + $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.';