W3cubDocs

/Drupal 8

public static function AssetResolver::sort

public static AssetResolver::sort($a, $b)

Sorts CSS and JavaScript resources.

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

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

$b: Second item for comparison.

Return value

int

File

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

Class

AssetResolver
The default asset resolver.

Namespace

Drupal\Core\Asset

Code

public static function sort($a, $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;
  }
  // Finally, order by weight.
  elseif ($a['weight'] < $b['weight']) {
    return -1;
  }
  elseif ($a['weight'] > $b['weight']) {
    return 1;
  }
  else {
    return 0;
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Asset!AssetResolver.php/function/AssetResolver::sort/8.1.x