public function SingleLanguageNegotiationUrl::processInbound in Single Language URL Prefix 8
Same name and namespace in other branches
- 2.0.x src/SingleLanguageNegotiationUrl.php \Drupal\single_language_url_prefix\SingleLanguageNegotiationUrl::processInbound()
Processes the inbound path.
Implementations may make changes to the request object passed in but should avoid all other side effects. This method can be called to process requests other than the current request.
Parameters
string $path: The path to process, with a leading slash.
\Symfony\Component\HttpFoundation\Request $request: The HttpRequest object representing the request to process. Note, if this method is being called via the path_processor_manager service and is not part of routing, the current request object must be cloned before being passed in.
Return value
string The processed path.
Overrides InboundPathProcessorInterface::processInbound
File
- src/
SingleLanguageNegotiationUrl.php, line 71
Class
- SingleLanguageNegotiationUrl
- Class for identifying language via URL prefix when there is single language.
Namespace
Drupal\single_language_url_prefixCode
public function processInbound($path, Request $request) {
$languages = $this->languageManager
->getLanguages();
// We don't do anything if more then one language enabled.
// That works by default.
if (count($languages) > 1 || $this
->isPathExcluded($path)) {
return $path;
}
$config = $this->config
->get('language.negotiation')
->get('url');
$source = $config['source'] ?? '';
if ($source === LanguageNegotiationUrl::CONFIG_PATH_PREFIX) {
$parts = explode('/', trim($path, '/'));
$prefix = array_shift($parts);
$language = reset($languages);
if (isset($config['prefixes'][$language
->getId()]) && $config['prefixes'][$language
->getId()] == $prefix) {
// Rebuild $path with the language removed.
$path = '/' . implode('/', $parts);
}
}
return $path;
}