You are here

protected function LanguageNegotiationContentEntity::hasLowerLanguageNegotiationWeight in Drupal 8

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

Determines if content entity language negotiator has higher priority.

The content entity language negotiator having higher priority than the url language negotiator, is a criteria in \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationContentEntity::processOutbound().

Return value

bool TRUE if the content entity language negotiator has higher priority than the url language negotiator, FALSE otherwise.

1 call to LanguageNegotiationContentEntity::hasLowerLanguageNegotiationWeight()
LanguageNegotiationContentEntity::processOutbound in core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php
Processes the outbound path.

File

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

Class

LanguageNegotiationContentEntity
Class for identifying the content translation language.

Namespace

Drupal\language\Plugin\LanguageNegotiation

Code

protected function hasLowerLanguageNegotiationWeight() {
  if (!isset($this->hasLowerLanguageNegotiationWeightResult)) {

    // Only run if the LanguageNegotiationContentEntity outbound function is
    // being executed before the outbound function of LanguageNegotiationUrl.
    $content_method_weights = $this->config
      ->get('language.types')
      ->get('negotiation.language_content.enabled') ?: [];

    // Check if the content language is configured to be dependent on the
    // url negotiator directly or indirectly over the interface negotiator.
    if (isset($content_method_weights[LanguageNegotiationUrl::METHOD_ID]) && $content_method_weights[static::METHOD_ID] > $content_method_weights[LanguageNegotiationUrl::METHOD_ID]) {
      $this->hasLowerLanguageNegotiationWeightResult = FALSE;
    }
    else {
      $check_interface_method = FALSE;
      if (isset($content_method_weights[LanguageNegotiationUI::METHOD_ID])) {
        $interface_method_weights = $this->config
          ->get('language.types')
          ->get('negotiation.language_interface.enabled') ?: [];
        $check_interface_method = isset($interface_method_weights[LanguageNegotiationUrl::METHOD_ID]);
      }
      if ($check_interface_method) {
        $max_weight = $content_method_weights[LanguageNegotiationUI::METHOD_ID];
        $max_weight = isset($content_method_weights[LanguageNegotiationUrl::METHOD_ID]) ? max($max_weight, $content_method_weights[LanguageNegotiationUrl::METHOD_ID]) : $max_weight;
      }
      else {
        $max_weight = isset($content_method_weights[LanguageNegotiationUrl::METHOD_ID]) ? $content_method_weights[LanguageNegotiationUrl::METHOD_ID] : PHP_INT_MAX;
      }
      $this->hasLowerLanguageNegotiationWeightResult = $content_method_weights[static::METHOD_ID] < $max_weight;
    }
  }
  return $this->hasLowerLanguageNegotiationWeightResult;
}