function LanguageNegotiationContentEntity::hasLowerLanguageNegotiationWeight

Same name in other branches
  1. 9 core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationContentEntity::hasLowerLanguageNegotiationWeight()
  2. 8.9.x core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationContentEntity::hasLowerLanguageNegotiationWeight()
  3. 11.x 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

File

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

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 = $content_method_weights[LanguageNegotiationUrl::METHOD_ID] ?? PHP_INT_MAX;
            }
            $this->hasLowerLanguageNegotiationWeightResult = $content_method_weights[static::METHOD_ID] < $max_weight;
        }
    }
    return $this->hasLowerLanguageNegotiationWeightResult;
}

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