Skip to content
This repository has been archived by the owner on Jun 22, 2020. It is now read-only.

Commit

Permalink
convert optional module sorting from callback to sorting function
Browse files Browse the repository at this point in the history
  • Loading branch information
tjwelde committed Mar 13, 2017
1 parent fca6096 commit 050f61d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Installer/Form/ModuleConfigureForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {

$providers = $this->optionalModulesManager->getDefinitions();

uasort($providers, static::sortWeights());
static::sortByWeights($providers);

foreach ($providers as $provider) {

Expand Down Expand Up @@ -138,19 +138,19 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
* 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.
*
* @return \Closure
* The sorting function
* @param array $array
* The array to be sorted.
*/
private static function sortWeights() {
return function ($a, $b) {
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;
};
});
}

}

0 comments on commit 050f61d

Please sign in to comment.