summaryrefslogtreecommitdiffstats
path: root/core/lib/Drupal/Core/EventSubscriber/LanguageRequestSubscriber.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/lib/Drupal/Core/EventSubscriber/LanguageRequestSubscriber.php')
-rw-r--r--core/lib/Drupal/Core/EventSubscriber/LanguageRequestSubscriber.php63
1 files changed, 63 insertions, 0 deletions
diff --git a/core/lib/Drupal/Core/EventSubscriber/LanguageRequestSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/LanguageRequestSubscriber.php
new file mode 100644
index 0000000..9a05a28
--- /dev/null
+++ b/core/lib/Drupal/Core/EventSubscriber/LanguageRequestSubscriber.php
@@ -0,0 +1,63 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\EventSubscriber\LanguageRequestSubscriber.
+ */
+
+namespace Drupal\Core\EventSubscriber;
+
+use Drupal\Core\Language\LanguageManager;
+use Symfony\Component\HttpKernel\HttpKernelInterface;
+use Symfony\Component\HttpKernel\KernelEvents;
+use Symfony\Component\HttpKernel\Event\GetResponseEvent;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+
+/**
+ * Sets the $request property on the language manager.
+ */
+class LanguageRequestSubscriber implements EventSubscriberInterface {
+
+ /**
+ * The language manager service.
+ *
+ * @var \Drupal\Core\Language\LanguageManager
+ */
+ protected $languageManager;
+
+ /**
+ * Constructs a LanguageRequestSubscriber object.
+ *
+ * @param \Drupal\Core\Language\LanguageManager $language_manager
+ * The language manager service.
+ *
+ */
+ public function __construct(LanguageManager $language_manager) {
+ $this->languageManager = $language_manager;
+ }
+
+ /**
+ * Sets the request on the language manager.
+ *
+ * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
+ * The Event to process.
+ */
+ public function onKernelRequestLanguage(GetResponseEvent $event) {
+ if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) {
+ $this->languageManager->setRequest($event->getRequest());
+ }
+ }
+
+ /**
+ * Registers the methods in this class that should be listeners.
+ *
+ * @return array
+ * An array of event listener definitions.
+ */
+ static function getSubscribedEvents() {
+ $events[KernelEvents::REQUEST][] = array('onKernelRequestLanguage', 300);
+
+ return $events;
+ }
+
+}