You are here

public function UserProtectionPluginCollection::pluginInstancesSort in User protect 8

Sorts plugin instances based on weight, label, provider or id.

Parameters

\Drupal\userprotect\Plugin\UserProtection\UserProtectionInterface $a: The first plugin in the comparison.

\Drupal\userprotect\Plugin\UserProtection\UserProtectionInterface $b: The second plugin in the comparison.

Return value

int -1 if $a should go first. 1 if $b should go first. 0 if it's unknown which should go first.

File

src/Plugin/UserProtection/UserProtectionPluginCollection.php, line 92

Class

UserProtectionPluginCollection
A collection of protection rules.

Namespace

Drupal\userprotect\Plugin\UserProtection

Code

public function pluginInstancesSort(UserProtectionInterface $a, UserProtectionInterface $b) {
  if ($a
    ->getWeight() != $b
    ->getWeight()) {
    return $a
      ->getWeight() < $b
      ->getWeight() ? -1 : 1;
  }
  if ($a
    ->label() != $b
    ->label()) {
    return strnatcasecmp($a
      ->label(), $b
      ->label());
  }
  if ($a->provider != $b->provider) {
    return strnatcasecmp($a->provider, $b->provider);
  }
  return strnatcasecmp($a
    ->getPluginId(), $b
    ->getPluginId());
}