initializeType example

/** * {@inheritdoc} */
  public function getCurrentLanguage($type = LanguageInterface::TYPE_INTERFACE) {
    if (!isset($this->negotiatedLanguages[$type])) {
      // Ensure we have a valid value for this language type.       $this->negotiatedLanguages[$type] = $this->getDefaultLanguage();

      if ($this->negotiator && $this->isMultilingual()) {
        if (!isset($this->initializing[$type])) {
          $this->initializing[$type] = TRUE;
          $negotiation = $this->negotiator->initializeType($type);
          $this->negotiatedLanguages[$type] = reset($negotiation);
          $this->negotiatedMethods[$type] = key($negotiation);
          unset($this->initializing[$type]);
        }
        // If the current interface language needs to be retrieved during         // initialization we return the system language. This way string         // translation calls happening during initialization will return the         // original strings which can be translated by calling them again         // afterwards. This can happen for instance while parsing negotiation         // method definitions.         elseif ($type == LanguageInterface::TYPE_INTERFACE) {
          
// Test unavailable plugin.     $config = $this->config('language.types');
    $config->set('configurable', [LanguageInterface::TYPE_URL]);
    $config->set('negotiation.language_url.enabled', [
      self::CLASS => -3,
    ]);
    $config->save();
    $languageNegotiator = $this->container->get('language_negotiator');
    $languageNegotiator->setCurrentUser($this->prophesize('Drupal\Core\Session\AccountInterface')->reveal());
    try {
      $languageNegotiator->initializeType(LanguageInterface::TYPE_URL);
    }
    catch (PluginNotFoundException $exception) {
      $this->fail('Plugin not found exception unhandled.');
    }
    $log_message = $logger->cleanLogs()[0];
    $this->assertEquals('error', $log_message[0]);
    $this->assertStringContainsString('The "Drupal\Tests\language\Kernel\LanguageNegotiatorPluginTest" plugin does not exist.', $log_message[1]);
  }

}
Home | Imprint | This part of the site doesn't use cookies.