You are here

public function RecipientGatewayEvent::getGatewaysSorted in SMS Framework 8

Same name and namespace in other branches
  1. 2.x src/Event/RecipientGatewayEvent.php \Drupal\sms\Event\RecipientGatewayEvent::getGatewaysSorted()
  2. 2.1.x src/Event/RecipientGatewayEvent.php \Drupal\sms\Event\RecipientGatewayEvent::getGatewaysSorted()

Return gateways ordered by priority from highest to lowest.

Return value

\Drupal\sms\Entity\SmsGatewayInterface[] An array of gateways ordered by priority from highest to lowest.

File

src/Event/RecipientGatewayEvent.php, line 80

Class

RecipientGatewayEvent
Event fired to determine valid gateways for a recipient.

Namespace

Drupal\sms\Event

Code

public function getGatewaysSorted() {
  $sorted = $this->gateways;
  uasort($sorted, function ($a, $b) {
    list(, $priority_a) = $a;
    list(, $priority_b) = $b;
    if ($priority_a == $priority_b) {
      return 0;
    }
    return $priority_a > $priority_b ? -1 : 1;
  });

  // Return the gateway object instead of tuples.
  $gateways = [];
  foreach ($sorted as $tuple) {
    list($gateway, ) = $tuple;
    $gateways[] = $gateway;
  }
  return $gateways;
}