You are here

public static function Language::sort in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Language/Language.php \Drupal\Core\Language\Language::sort()

Sort language objects.

Parameters

\Drupal\Core\Language\LanguageInterface[] $languages: The array of language objects keyed by langcode.

3 calls to Language::sort()
ConfigurableLanguageManager::getLanguages in core/modules/language/src/ConfigurableLanguageManager.php
Returns a list of languages set up on the site.
ConfigurableLanguageManager::getNativeLanguages in core/modules/language/src/ConfigurableLanguageManager.php
Returns a list of languages set up on the site in their native form.
LanguageUnitTest::testSortArrayOfLanguages in core/tests/Drupal/Tests/Core/Language/LanguageUnitTest.php
Tests sorting an array of language objects.

File

core/lib/Drupal/Core/Language/Language.php, line 149
Contains \Drupal\Core\Language\Language.

Class

Language
An object containing the information for an interface language.

Namespace

Drupal\Core\Language

Code

public static function sort(&$languages) {
  uasort($languages, function (LanguageInterface $a, LanguageInterface $b) {
    $a_weight = $a
      ->getWeight();
    $b_weight = $b
      ->getWeight();
    if ($a_weight == $b_weight) {
      return strnatcasecmp($a
        ->getName(), $b
        ->getName());
    }
    return $a_weight < $b_weight ? -1 : 1;
  });
}