You are here

public function RouteSubscriber::routes in SMS Framework 2.1.x

Same name and namespace in other branches
  1. 8 src/Routing/RouteSubscriber.php \Drupal\sms\Routing\RouteSubscriber::routes()
  2. 2.x src/Routing/RouteSubscriber.php \Drupal\sms\Routing\RouteSubscriber::routes()

Returns a set of route objects.

Return value

\Symfony\Component\Routing\RouteCollection A route collection.

1 string reference to 'RouteSubscriber::routes'
sms.routing.yml in ./sms.routing.yml
sms.routing.yml

File

src/Routing/RouteSubscriber.php, line 51

Class

RouteSubscriber
Subscriber for SMS Framework routes.

Namespace

Drupal\sms\Routing

Code

public function routes() {
  $sms_settings = $this->configFactory
    ->get('sms.settings');
  $collection = new RouteCollection();

  // Phone number verification.
  $path_verify = $sms_settings
    ->get('page.verify');

  // String length must include at least a slash + another character.
  if (isset($path_verify) && mb_strlen($path_verify) >= 2) {
    $collection
      ->add('sms.phone.verify', new Route($path_verify, [
      '_form' => '\\Drupal\\sms\\Form\\VerifyPhoneNumberForm',
      '_title' => 'Verify a phone number',
    ], [
      '_permission' => 'sms verify phone number',
    ]));
  }

  /** @var \Drupal\sms\Entity\SmsGatewayInterface $gateway */
  foreach (SmsGateway::loadMultiple() as $id => $gateway) {
    if ($gateway
      ->supportsReportsPush()) {
      $path = $gateway
        ->getPushReportPath();
      if (isset($path) && mb_strlen($path) >= 2 && mb_substr($path, 0, 1) == '/') {
        $route = (new Route($path))
          ->setDefault('_controller', '\\Drupal\\sms\\DeliveryReportController::processDeliveryReport')
          ->setDefault('_sms_gateway_push_endpoint', $id)
          ->setRequirement('_sms_gateway_supports_pushed_reports', 'TRUE');
        $collection
          ->add('sms.delivery_report.receive.' . $id, $route);
      }
    }
    if ($gateway
      ->autoCreateIncomingRoute()) {
      $path = $gateway
        ->getPushIncomingPath();
      if (isset($path) && mb_strlen($path) >= 2 && mb_substr($path, 0, 1) == '/') {
        $parameters['sms_gateway']['type'] = 'entity:sms_gateway';
        $route = (new Route($path))
          ->setDefault('sms_gateway', $id)
          ->setDefault('_controller', '\\Drupal\\sms\\SmsIncomingController::processIncoming')
          ->setRequirement('_access', 'TRUE')
          ->setOption('parameters', $parameters)
          ->setMethods([
          'POST',
        ]);
        $collection
          ->add('sms.incoming.receive.' . $id, $route);
      }
    }
  }
  return $collection;
}