3 namespace Drupal\menu_test\Controller;
5 use Drupal\Core\Controller\ControllerBase;
6 use Drupal\Core\Routing\RouteMatchInterface;
7 use Drupal\Core\Theme\ThemeManagerInterface;
8 use Drupal\Core\Theme\ThemeNegotiatorInterface;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
12 * Controller routines for menu_test routes.
14 class MenuTestController extends ControllerBase {
19 * @var \Drupal\Core\Theme\ThemeManagerInterface
21 protected $themeManager;
24 * The theme negotiator.
26 * @var \Drupal\Core\Theme\ThemeNegotiatorInterface
28 protected $themeNegotiator;
31 * The active route match.
33 * @var \Drupal\Core\Routing\RouteMatchInterface
35 protected $routeMatch;
38 * Constructs the MenuTestController object.
40 * @param \Drupal\menu_test\Controller\ThemeManagerInterface $theme_manager
42 * @param \Drupal\menu_test\Controller\ThemeNegotiatorInterface $theme_negotiator
43 * The theme negotiator.
44 * @param \Drupal\menu_test\Controller\RouteMatchInterface $route_match
45 * The current route match.
47 public function __construct(ThemeManagerInterface $theme_manager, ThemeNegotiatorInterface $theme_negotiator, RouteMatchInterface $route_match) {
48 $this->themeManager = $theme_manager;
49 $this->themeNegotiator = $theme_negotiator;
50 $this->routeMatch = $route_match;
56 public static function create(ContainerInterface $container) {
58 $container->get('theme.manager'),
59 $container->get('theme.negotiator'),
60 $container->get('current_route_match')
65 * Some known placeholder content which can be used for testing.
68 * A string that can be used for comparison.
70 public function menuTestCallback() {
71 return ['#markup' => 'This is the menuTestCallback content.'];
76 * A title callback method for test routes.
78 * @param array $_title_arguments
79 * Optional array from the route defaults.
80 * @param string $_title
81 * Optional _title string from the route defaults.
86 public function titleCallback(array $_title_arguments = [], $_title = '') {
87 $_title_arguments += ['case_number' => '2', 'title' => $_title];
88 return t($_title_arguments['title']) . ' - Case ' . $_title_arguments['case_number'];
92 * Page callback: Tests the theme negotiation functionality.
94 * @param bool $inherited
95 * TRUE when the requested page is intended to inherit
96 * the theme of its parent.
99 * A string describing the requested custom theme and actual
101 * for the current page request.
103 public function themePage($inherited) {
104 $theme_key = $this->themeManager->getActiveTheme()->getName();
105 // Now we check what the theme negotiator service returns.
106 $active_theme = $this->themeNegotiator
107 ->determineActiveTheme($this->routeMatch);
108 $output = "Active theme: $active_theme. Actual theme: $theme_key.";
110 $output .= ' Theme negotiation inheritance is being tested.';
112 return ['#markup' => $output];
116 * A title callback for XSS breadcrumb check.
120 public function breadcrumbTitleCallback() {
121 return '<script>alert(123);</script>';