function LanguageNegotiationContentEntity::processOutbound

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

Overrides OutboundPathProcessorInterface::processOutbound

File

core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php, line 108

Class

LanguageNegotiationContentEntity
Class for identifying the content translation language.

Namespace

Drupal\language\Plugin\LanguageNegotiation

Code

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'][static::QUERY_PARAMETER])) {
            $options['query'][static::QUERY_PARAMETER] = $langcode;
        }
        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;
}

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