Pull merge.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / service / theme-negotiator.twig
1 <?php
2
3 namespace Drupal\{{ machine_name }}\Theme;
4
5 use Drupal\Core\Routing\RouteMatchInterface;
6 use Drupal\Core\Theme\ThemeNegotiatorInterface;
7 use Symfony\Component\HttpFoundation\RequestStack;
8
9 /**
10  * Defines a theme negotiator that deals with the active theme on example page.
11  */
12 class {{ class }} implements ThemeNegotiatorInterface {
13
14   /**
15    * The request stack.
16    *
17    * @var \Symfony\Component\HttpFoundation\RequestStack
18    */
19   protected $requestStack;
20
21   /**
22    * Constructs a new {{ class }}.
23    *
24    * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
25    *   The request stack used to retrieve the current request.
26    */
27   public function __construct(RequestStack $request_stack) {
28     $this->requestStack = $request_stack;
29   }
30
31   /**
32    * {@inheritdoc}
33    */
34   public function applies(RouteMatchInterface $route_match) {
35     return $route_match->getRouteName() == '{{ machine_name }}.example';
36   }
37
38   /**
39    * {@inheritdoc}
40    */
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)) {
45       return $theme;
46     }
47   }
48
49 }