| 7 common.inc | drupal_sort_weight($a, $b) |
| 8 common.inc | drupal_sort_weight($a, $b) |
Sorts a structured array by the 'weight' element.
Note that the sorting is by the 'weight' array element, not by the render element property '#weight'.
Callback for uasort() used in various functions.
Parameters
$a: First item for comparison. The compared items should be associative arrays that optionally include a 'weight' element. For items without a 'weight' element, a default value of 0 will be used.
$b: Second item for comparison.
12 string references to 'drupal_sort_weight'
- ConfigEntityListTest::testList in core/
modules/ config/ lib/ Drupal/ config/ Tests/ ConfigEntityListTest.php - Tests entity list controller methods.
- Display::sortBlocks in core/
modules/ layout/ lib/ Drupal/ layout/ Plugin/ Core/ Entity/ Display.php - Transform the stored blockConfig into a sorted, region-oriented array.
- drupal_get_filetransfer_info in core/
includes/ common.inc - Assembles the Drupal FileTransfer registry.
- drupal_get_updaters in core/
includes/ common.inc - Assembles the Drupal Updater registry.
- EntityListController::buildOperations in core/
lib/ Drupal/ Core/ Entity/ EntityListController.php - Builds a renderable list of operation links for the entity.
File
- core/
includes/ common.inc, line 5739 - Common functions that many Drupal modules will need to reference.
Code
function drupal_sort_weight($a, $b) {
$a_weight = (is_array($a) && isset($a['weight'])) ? $a['weight'] : 0;
$b_weight = (is_array($b) && isset($b['weight'])) ? $b['weight'] : 0;
if ($a_weight == $b_weight) {
return 0;
}
return ($a_weight < $b_weight) ? -1 : 1;
}