You are here

public function Subscribe::alterRouteDefinition in Mailing List 8

Allows access plugins to alter the route definition of a view.

Likely the access plugin will add new requirements, so its custom access checker can be applied.

Parameters

\Symfony\Component\Routing\Route $route: The route to change.

Overrides AccessPluginBase::alterRouteDefinition

File

src/Plugin/views/access/Subscribe.php, line 100

Class

Subscribe
Views access plugin that provides access for mailing list subscribers.

Namespace

Drupal\mailing_list\Plugin\views\access

Code

public function alterRouteDefinition(Route $route) {

  // Add all subscribe permissions in OR logic.
  $perms = '';
  foreach ($this->entityManager
    ->getStorage('mailing_list')
    ->loadMultiple() as $mailing_list) {
    $perm = 'subscribe to ' . $mailing_list
      ->id() . ' mailing list';
    $perms .= empty($perms) ? $perm : '+' . $perm;
  }
  if (!empty($perms)) {
    $route
      ->setRequirement('_permission', $perms);
  }
}