You are here

public static function TaxType::sort in Commerce Core 8.2

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

Overrides ConfigEntityBase::sort

File

modules/tax/src/Entity/TaxType.php, line 178

Class

TaxType
Defines the tax type entity class.

Namespace

Drupal\commerce_tax\Entity

Code

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

  /** @var \Drupal\commerce_tax\Entity\TaxTypeInterface $a */

  /** @var \Drupal\commerce_tax\Entity\TaxTypeInterface $b */
  $a_plugin = $a
    ->getPlugin();
  $b_plugin = $b
    ->getPlugin();
  $a_weight = $a_plugin ? $a_plugin
    ->getWeight() : 0;
  $b_weight = $b_plugin ? $b_plugin
    ->getWeight() : 0;
  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;
}