You are here

public static function Promotion::sort in Commerce Core 8.2

Helper callback for uasort() to sort promotions by weight and label.

Parameters

\Drupal\commerce_promotion\Entity\PromotionInterface $a: The first promotion to sort.

\Drupal\commerce_promotion\Entity\PromotionInterface $b: The second promotion to sort.

Return value

int The comparison result for uasort().

File

modules/promotion/src/Entity/Promotion.php, line 914

Class

Promotion
Defines the promotion entity class.

Namespace

Drupal\commerce_promotion\Entity

Code

public static function sort(PromotionInterface $a, PromotionInterface $b) {
  $a_weight = $a
    ->getWeight();
  $b_weight = $b
    ->getWeight();
  if ($a_weight == $b_weight) {
    $a_label = $a
      ->label();
    $b_label = $b
      ->label();
    return strnatcasecmp($a_label, $b_label);
  }
  return $a_weight < $b_weight ? -1 : 1;
}