Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / service / theme-negotiator.twig
diff --git a/vendor/chi-teck/drupal-code-generator/templates/d8/service/theme-negotiator.twig b/vendor/chi-teck/drupal-code-generator/templates/d8/service/theme-negotiator.twig
new file mode 100644 (file)
index 0000000..1c63e6b
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+
+namespace Drupal\{{ machine_name }}\Theme;
+
+use Drupal\Core\Routing\RouteMatchInterface;
+use Drupal\Core\Theme\ThemeNegotiatorInterface;
+use Symfony\Component\HttpFoundation\RequestStack;
+
+/**
+ * Defines a theme negotiator that deals with the active theme on example page.
+ */
+class {{ class }} implements ThemeNegotiatorInterface {
+
+  /**
+   * The request stack.
+   *
+   * @var \Symfony\Component\HttpFoundation\RequestStack
+   */
+  protected $requestStack;
+
+  /**
+   * Constructs a new {{ class }}.
+   *
+   * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
+   *   The request stack used to retrieve the current request.
+   */
+  public function __construct(RequestStack $request_stack) {
+    $this->requestStack = $request_stack;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function applies(RouteMatchInterface $route_match) {
+    return $route_match->getRouteName() == '{{ machine_name }}.example';
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function determineActiveTheme(RouteMatchInterface $route_match) {
+    // Allow users to pass theme name through 'theme' query parameter.
+    $theme = $this->requestStack->getCurrentRequest()->query->get('theme');
+    if (is_string($theme)) {
+      return $theme;
+    }
+  }
+
+}