3 namespace Drupal\{{ machine_name }}\Theme;
5 use Drupal\Core\Routing\RouteMatchInterface;
6 use Drupal\Core\Theme\ThemeNegotiatorInterface;
7 use Symfony\Component\HttpFoundation\RequestStack;
10 * Defines a theme negotiator that deals with the active theme on example page.
12 class {{ class }} implements ThemeNegotiatorInterface {
17 * @var \Symfony\Component\HttpFoundation\RequestStack
19 protected $requestStack;
22 * Constructs a new {{ class }}.
24 * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
25 * The request stack used to retrieve the current request.
27 public function __construct(RequestStack $request_stack) {
28 $this->requestStack = $request_stack;
34 public function applies(RouteMatchInterface $route_match) {
35 return $route_match->getRouteName() == '{{ machine_name }}.example';
41 public function determineActiveTheme(RouteMatchInterface $route_match) {
42 // Allow users to pass theme name through 'theme' query parameter.
43 $theme = $this->requestStack->getCurrentRequest()->query->get('theme');
44 if (is_string($theme)) {