You are here

public function DomainStorage::sort in Domain Access 8

Sorts domains by weight.

For use by loadMultipleSorted().

Parameters

DomainInterface $a: The first Domain object to sort.

DomainInterface $b: The Domain object to compare against.

Return value

bool Wether the first domain weight is greater or not.

Overrides DomainStorageInterface::sort

File

domain/src/DomainStorage.php, line 128

Class

DomainStorage
Loads Domain records.

Namespace

Drupal\domain

Code

public function sort(DomainInterface $a, DomainInterface $b) {

  // Prioritize the weights.
  $weight_difference = $a
    ->getWeight() - $b
    ->getWeight();
  if ($weight_difference !== 0) {
    return $weight_difference;
  }

  // Fallback to the labels if the weights are equal.
  return strcmp($a
    ->label(), $b
    ->label());
}