class LanguageRequestSubscriber in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/language/src/EventSubscriber/LanguageRequestSubscriber.php \Drupal\language\EventSubscriber\LanguageRequestSubscriber
Sets the $request property on the language manager.
Hierarchy
- class \Drupal\language\EventSubscriber\LanguageRequestSubscriber implements EventSubscriberInterface
Expanded class hierarchy of LanguageRequestSubscriber
File
- core/
modules/ language/ src/ EventSubscriber/ LanguageRequestSubscriber.php, line 22 - Contains \Drupal\language\EventSubscriber\LanguageRequestSubscriber.
Namespace
Drupal\language\EventSubscriberView source
class LanguageRequestSubscriber implements EventSubscriberInterface {
/**
* The language manager service.
*
* @var \Drupal\language\ConfigurableLanguageManagerInterface
*/
protected $languageManager;
/**
* The language negotiator.
*
* @var \Drupal\language\LanguageNegotiatorInterface
*/
protected $negotiator;
/**
* The translation service.
*
* @var \Drupal\Core\StringTranslation\Translator\TranslatorInterface;
*/
protected $translation;
/**
* The current active user.
*
* @return \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* Constructs a LanguageRequestSubscriber object.
*
* @param \Drupal\language\ConfigurableLanguageManagerInterface $language_manager
* The language manager service.
* @param \Drupal\language\LanguageNegotiatorInterface
* The language negotiator.
* @param \Drupal\Core\StringTranslation\Translator\TranslatorInterface $translation;
* The translation service.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current active user.
*/
public function __construct(ConfigurableLanguageManagerInterface $language_manager, LanguageNegotiatorInterface $negotiator, TranslatorInterface $translation, AccountInterface $current_user) {
$this->languageManager = $language_manager;
$this->negotiator = $negotiator;
$this->translation = $translation;
$this->currentUser = $current_user;
}
/**
* 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) {
$request = $event
->getRequest();
$this->negotiator
->setCurrentUser($this->currentUser);
$this->negotiator
->reset();
if ($this->languageManager instanceof ConfigurableLanguageManagerInterface) {
$this->languageManager
->setNegotiator($this->negotiator);
$this->languageManager
->setConfigOverrideLanguage($this->languageManager
->getCurrentLanguage());
}
// After the language manager has initialized, set the default langcode
// for the string translations.
$langcode = $this->languageManager
->getCurrentLanguage()
->getId();
$this->translation
->setDefaultLangcode($langcode);
}
}
/**
* 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',
255,
);
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LanguageRequestSubscriber:: |
protected | property | The current active user. | |
LanguageRequestSubscriber:: |
protected | property | The language manager service. | |
LanguageRequestSubscriber:: |
protected | property | The language negotiator. | |
LanguageRequestSubscriber:: |
protected | property | The translation service. | |
LanguageRequestSubscriber:: |
static | function |
Registers the methods in this class that should be listeners. Overrides EventSubscriberInterface:: |
|
LanguageRequestSubscriber:: |
public | function | Sets the request on the language manager. | |
LanguageRequestSubscriber:: |
public | function | Constructs a LanguageRequestSubscriber object. |