public function LanguageNegotiationContentEntity::processOutbound in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationContentEntity::processOutbound()
Processes the outbound path.
Parameters
string $path: The path to process, with a leading slash.
array $options: (optional) An associative array of additional options, with the following elements:
- 'query': An array of query key/value-pairs (without any URL-encoding) to append to the URL.
- 'fragment': A fragment identifier (named anchor) to append to the URL. Do not include the leading '#' character.
- 'absolute': Defaults to FALSE. Whether to force the output to be an absolute link (beginning with http:). Useful for links that will be displayed outside the site, such as in an RSS feed.
- 'language': An optional language object used to look up the alias for the URL. If $options['language'] is omitted, it defaults to the current language for the language type LanguageInterface::TYPE_URL.
- 'https': Whether this URL should point to a secure location. If not defined, the current scheme is used, so the user stays on HTTP or HTTPS respectively. TRUE enforces HTTPS and FALSE enforces HTTP.
- 'base_url': Only used internally by a path processor, for example, to modify the base URL when a language dependent URL requires so.
- 'prefix': Only used internally, to modify the path when a language dependent URL requires so.
- 'route': The route object for the given path. It will be set by \Drupal\Core\Routing\UrlGenerator::generateFromRoute().
\Symfony\Component\HttpFoundation\Request $request: The HttpRequest object representing the current request.
\Drupal\Core\Render\BubbleableMetadata $bubbleable_metadata: (optional) Object to collect path processors' bubbleable metadata.
Return value
string The processed path.
Overrides OutboundPathProcessorInterface::processOutbound
File
- core/
modules/ language/ src/ Plugin/ LanguageNegotiation/ LanguageNegotiationContentEntity.php, line 108 - Contains \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationContentEntity.
Class
- LanguageNegotiationContentEntity
- Class for identifying the content translation language.
Namespace
Drupal\language\Plugin\LanguageNegotiationCode
public function processOutbound($path, &$options = [], Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
// If appropriate, process outbound to add a query parameter to the url and
// remove the language option, so that url negotiator does not rewrite the
// url.
// First, check if processing conditions are met.
if (!($request && !empty($options['route']) && $this
->hasLowerLanguageNegotiationWeight() && $this
->meetsContentEntityRoutesCondition($options['route'], $request))) {
return $path;
}
if (isset($options['language']) || ($langcode = $this
->getLangcode($request))) {
// If the language option is set, unset it, so that the url language
// negotiator does not rewrite the url.
if (isset($options['language'])) {
$langcode = $options['language']
->getId();
unset($options['language']);
}
if (isset($options['query']) && is_string($options['query'])) {
$query = [];
parse_str($options['query'], $query);
$options['query'] = $query;
}
else {
$options['query'] = [];
}
if (!isset($options['query'][static::QUERY_PARAMETER])) {
$query_addon = [
static::QUERY_PARAMETER => $langcode,
];
$options['query'] += $query_addon;
// @todo Remove this once https://www.drupal.org/node/2507005 lands.
$path .= (strpos($path, '?') !== FALSE ? '&' : '?') . UrlHelper::buildQuery($query_addon);
}
if ($bubbleable_metadata) {
// Cached URLs that have been processed by this outbound path
// processor must be:
$bubbleable_metadata
->addCacheContexts([
'url.query_args:' . static::QUERY_PARAMETER,
]);
}
}
return $path;
}