private static function ModuleConfigureForm::sortByWeights in Thunder 8.3
Same name and namespace in other branches
- 8.2 src/Installer/Form/ModuleConfigureForm.php \Drupal\thunder\Installer\Form\ModuleConfigureForm::sortByWeights()
- 8.4 src/Installer/Form/ModuleConfigureForm.php \Drupal\thunder\Installer\Form\ModuleConfigureForm::sortByWeights()
Returns a sorting function to sort an array by weights.
If an array element doesn't provide a weight, it will be set to 0. If two elements have the same weight, they are sorted by label.
Parameters
array $array: The array to be sorted.
1 call to ModuleConfigureForm::sortByWeights()
- ModuleConfigureForm::buildForm in src/
Installer/ Form/ ModuleConfigureForm.php - Form constructor.
File
- src/
Installer/ Form/ ModuleConfigureForm.php, line 149
Class
- ModuleConfigureForm
- Provides the site configuration form.
Namespace
Drupal\thunder\Installer\FormCode
private static function sortByWeights(array &$array) {
uasort($array, function ($a, $b) {
$a_weight = isset($a['weight']) ? $a['weight'] : 0;
$b_weight = isset($b['weight']) ? $b['weight'] : 0;
if ($a_weight == $b_weight) {
return $a['label'] > $b['label'] ? 1 : -1;
}
return $a_weight > $b_weight ? 1 : -1;
});
}