You are here

public function ContextManager::sortContextsByWeight in Context 8.0

Same name and namespace in other branches
  1. 8.4 src/ContextManager.php \Drupal\context\ContextManager::sortContextsByWeight()
  2. 8 src/ContextManager.php \Drupal\context\ContextManager::sortContextsByWeight()

Sorts an array of context entities by their weight.

Callback for uasort().

Parameters

ContextInterface $a: First item for comparison.

ContextInterface $b: Second item for comparison.

Return value

int The comparison result for uasort().

File

src/ContextManager.php, line 315

Class

ContextManager
This is the manager service for the context module and should not be confused with the built in contexts in Drupal.

Namespace

Drupal\context

Code

public function sortContextsByWeight(ContextInterface $a, ContextInterface $b) {
  if ($a
    ->getWeight() == $b
    ->getWeight()) {
    return 0;
  }
  return $a
    ->getWeight() < $b
    ->getWeight() ? -1 : 1;
}