function public static function SettingManager::sort

8.x-3.x SettingManager.php public static SettingManager::sort(array $a, array $b)

Sorts the setting plugin definitions.

Sorts setting plugin definitions in the following order:

  • First by top level group.
  • Then by sub-groups.
  • Then by weight.
  • Then by identifier.


array $a: First plugin definition for comparison.

array $b: Second plugin definition for comparison.

Return value

int The comparison result.


Manages discovery and instantiation of Bootstrap theme settings.



Source src/Plugin/SettingManager.php (line 63)

public static function sort(array $a, array $b) {
  $aIndex = static::getTopLevelGroupIndex($a);
  $bIndex = static::getTopLevelGroupIndex($b);

  // Top level group isn't the same, sort by index.
  if ($aIndex !== $bIndex) {
    return $aIndex - $bIndex;

  // Next sort by all groups (sub-groups).
  $result = SortArray::sortByKeyString($a, $b, 'groups');

  // Groups are the same.
  if ($result === 0) {
    // Sort by weight.
    $result = SortArray::sortByWeightElement($a, $b);

    // Weights are the same.
    if ($result === 0) {
      // Sort by plugin identifier.
      $result = SortArray::sortByKeyString($a, $b, 'id');

  return $result;