You are here

public static function AssetResolver::sort in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Asset/AssetResolver.php \Drupal\Core\Asset\AssetResolver::sort()
  2. 9 core/lib/Drupal/Core/Asset/AssetResolver.php \Drupal\Core\Asset\AssetResolver::sort()

Sorts CSS and JavaScript resources.

Callback for uasort().

This sort order helps optimize front-end performance while providing modules and themes with the necessary control for ordering the CSS and JavaScript appearing on a page.

Parameters

array $a: First item for comparison. The compared items should be associative arrays of member items.

array $b: Second item for comparison.

Return value

int The comparison result for uasort().

File

core/lib/Drupal/Core/Asset/AssetResolver.php, line 357

Class

AssetResolver
The default asset resolver.

Namespace

Drupal\Core\Asset

Code

public static function sort(array $a, array $b) {

  // First order by group, so that all items in the CSS_AGGREGATE_DEFAULT
  // group appear before items in the CSS_AGGREGATE_THEME group. Modules may
  // create additional groups by defining their own constants.
  if ($a['group'] < $b['group']) {
    return -1;
  }
  elseif ($a['group'] > $b['group']) {
    return 1;
  }
  elseif ($a['weight'] < $b['weight']) {
    return -1;
  }
  elseif ($a['weight'] > $b['weight']) {
    return 1;
  }
  else {
    return 0;
  }
}