public static Language::sort(&$languages)
Sort language objects.
Parameters
\Drupal\Core\Language\LanguageInterface[] $languages: The array of language objects keyed by langcode.
File
- core/lib/Drupal/Core/Language/Language.php, line 146
Class
- Language
- An object containing the information for an interface language.
Namespace
Drupal\Core\Language
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 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 ) { $a_name = $a ->getName(); $b_name = $b ->getName(); // If either name is a TranslatableMarkup object it can not be converted // to a string. This is because translation requires a sorted list of // languages thereby causing an infinite loop. Determine the order based // on ID if this is the case. if ( $a_name instanceof TranslatableMarkup || $b_name instanceof TranslatableMarkup) { $a_name = $a ->getId(); $b_name = $b ->getId(); } return strnatcasecmp ( $a_name , $b_name ); } return ( $a_weight < $b_weight ) ? -1 : 1; }); } |
Please login to continue.