You are here

public function LanguageNegotiationContentEntity::processOutbound in Drupal 10

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

File

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

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;
}