function Shortcut::sort

Same name and namespace in other branches
  1. 9 core/modules/shortcut/src/Entity/Shortcut.php \Drupal\shortcut\Entity\Shortcut::sort()
  2. 8.9.x core/modules/shortcut/src/Entity/Shortcut.php \Drupal\shortcut\Entity\Shortcut::sort()
  3. 10 core/modules/shortcut/src/Entity/Shortcut.php \Drupal\shortcut\Entity\Shortcut::sort()

Sort shortcut objects.

Callback for uasort().

Parameters

\Drupal\shortcut\ShortcutInterface $a: First item for comparison.

\Drupal\shortcut\ShortcutInterface $b: Second item for comparison.

Return value

int The comparison result for uasort().

File

core/modules/shortcut/src/Entity/Shortcut.php, line 182

Class

Shortcut
Defines the shortcut entity class.

Namespace

Drupal\shortcut\Entity

Code

public static function sort(ShortcutInterface $a, ShortcutInterface $b) {
    $a_weight = $a->getWeight();
    $b_weight = $b->getWeight();
    if ($a_weight == $b_weight) {
        return strnatcasecmp($a->getTitle(), $b->getTitle());
    }
    return $a_weight <=> $b_weight;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.