function LanguageConfigurationTest::getHighestConfigurableLanguageWeight

Same name in other branches
  1. 9 core/modules/language/tests/src/Functional/LanguageConfigurationTest.php \Drupal\Tests\language\Functional\LanguageConfigurationTest::getHighestConfigurableLanguageWeight()
  2. 8.9.x core/modules/language/tests/src/Functional/LanguageConfigurationTest.php \Drupal\Tests\language\Functional\LanguageConfigurationTest::getHighestConfigurableLanguageWeight()
  3. 11.x core/modules/language/tests/src/Functional/LanguageConfigurationTest.php \Drupal\Tests\language\Functional\LanguageConfigurationTest::getHighestConfigurableLanguageWeight()

Helper to get maximum weight of configurable (unlocked) languages.

Return value

int Maximum weight of configurable languages.

2 calls to LanguageConfigurationTest::getHighestConfigurableLanguageWeight()
LanguageConfigurationTest::checkConfigurableLanguageWeight in core/modules/language/tests/src/Functional/LanguageConfigurationTest.php
Validates system languages are ordered after configurable languages.
LanguageConfigurationTest::testLanguageConfigurationWeight in core/modules/language/tests/src/Functional/LanguageConfigurationTest.php
Functional tests for setting system language weight on adding, editing and deleting languages.

File

core/modules/language/tests/src/Functional/LanguageConfigurationTest.php, line 217

Class

LanguageConfigurationTest
Adds and configures languages to check negotiation changes.

Namespace

Drupal\Tests\language\Functional

Code

protected function getHighestConfigurableLanguageWeight() {
    $max_weight = 0;
    $storage = $this->container
        ->get('entity_type.manager')
        ->getStorage('configurable_language');
    $storage->resetCache();
    
    /** @var \Drupal\Core\Language\LanguageInterface[] $languages */
    $languages = $storage->loadMultiple();
    foreach ($languages as $language) {
        if (!$language->isLocked()) {
            $max_weight = max($max_weight, $language->getWeight());
        }
    }
    return $max_weight;
}

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