function LanguageNegotiationUrl::processInbound

Same name in other branches
  1. 9 core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl::processInbound()
  2. 8.9.x core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl::processInbound()
  3. 10 core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl::processInbound()

Overrides InboundPathProcessorInterface::processInbound

File

core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php, line 103

Class

LanguageNegotiationUrl
Class for identifying language via URL prefix or domain.

Namespace

Drupal\language\Plugin\LanguageNegotiation

Code

public function processInbound($path, Request $request) {
    $config = $this->config
        ->get('language.negotiation')
        ->get('url');
    if ($config['source'] == LanguageNegotiationUrl::CONFIG_PATH_PREFIX) {
        $parts = explode('/', trim($path, '/'));
        $prefix = array_shift($parts);
        // Search prefix within added languages.
        foreach ($this->languageManager
            ->getLanguages() as $language) {
            if (isset($config['prefixes'][$language->getId()]) && $config['prefixes'][$language->getId()] == $prefix) {
                // Rebuild $path with the language removed.
                $path = '/' . implode('/', $parts);
                break;
            }
        }
    }
    return $path;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.