You are here

public function LanguageNegotiationAdministrationLanguage::getLangcode in Administration Language Negotiation 8

Performs language negotiation.

Parameters

\Symfony\Component\HttpFoundation\Request $request: (optional) The current request. Defaults to NULL if it has not been initialized yet.

Return value

string A valid language code or FALSE if the negotiation was unsuccessful.

Overrides LanguageNegotiationMethodInterface::getLangcode

File

src/Plugin/LanguageNegotiation/LanguageNegotiationAdministrationLanguage.php, line 75

Class

LanguageNegotiationAdministrationLanguage
Class for identifying language from a administration language negotiation.

Namespace

Drupal\administration_language_negotiation\Plugin\LanguageNegotiation

Code

public function getLangcode(Request $request = NULL) {

  // Run only for allowed users.
  if ($this->currentUser
    ->hasPermission('use administration language negotiation')) {
    $config = $this->config
      ->get('administration_language_negotiation.negotiation');
    $manager = $this->conditionManager;
    foreach ($manager
      ->getDefinitions() as $def) {

      /** @var \Drupal\Core\Executable\ExecutableInterface $condition_plugin */
      $condition_plugin = $manager
        ->createInstance($def['id'], $config
        ->get());
      if (!$manager
        ->execute($condition_plugin)) {
        return $this->currentUser
          ->getPreferredAdminLangcode(FALSE);
      }
    }
  }
  return FALSE;
}