You are here

class RouteSubscriber in Vocabulary Permissions Per Role 8

Class RouteSubscriber.

@package Drupal\vppr\Routing

Hierarchy

Expanded class hierarchy of RouteSubscriber

1 string reference to 'RouteSubscriber'
vppr.services.yml in ./vppr.services.yml
vppr.services.yml
1 service uses RouteSubscriber
vppr.route_subscriber in ./vppr.services.yml
Drupal\vppr\Routing\RouteSubscriber

File

src/Routing/RouteSubscriber.php, line 13

Namespace

Drupal\vppr\Routing
View source
class RouteSubscriber extends RouteSubscriberBase {

  /**
   * {@inheritdoc}
   */
  public function alterRoutes(RouteCollection $collection) {

    // For all the necessary admin routes grant permission
    // (admin/structure/taxonomy).
    if ($route = $collection
      ->get('entity.taxonomy_vocabulary.collection')) {
      $route
        ->setRequirements([
        '_custom_access' => '\\vppr_route_access',
      ]);
      $route
        ->setOption('op', 'index');
    }

    // Overview page.
    // admin/structure/taxonomy/manage/{taxonomy_vocabulary}/overview.
    if ($route = $collection
      ->get('entity.taxonomy_vocabulary.overview_form')) {
      $route
        ->setRequirements([
        '_custom_access' => '\\vppr_route_access',
      ]);
      $route
        ->setOption('op', 'list terms');
    }

    // Vocabulary Edit form -
    // admin/structure/taxonomy/manage/{taxonomy_vocabulary}.
    if ($route = $collection
      ->get('entity.taxonomy_vocabulary.edit_form')) {
      $route
        ->setRequirements([
        '_custom_access' => '\\vppr_route_access',
      ]);
    }

    // Term Edit page - taxonomy/term/{taxonomy_term}/edit.
    if ($route = $collection
      ->get('entity.taxonomy_term.edit_form')) {
      $route
        ->setRequirements([
        '_custom_access' => '\\vppr_route_access',
      ]);
    }
    if ($route = $collection
      ->get('entity.taxonomy_term.add_form')) {
      $route
        ->setRequirements([
        '_custom_access' => '\\vppr_route_access',
      ]);
    }

    // Vocabulary delete - admin/structure/taxonomy/%vocabulary/delete.
    if ($route = $collection
      ->get('entity.taxonomy_vocabulary.delete_form')) {
      $route
        ->setRequirements([
        '_custom_access' => '\\vppr_route_access',
      ]);
    }

    // Term delete - taxonomy/term/{taxonomy_term}/delete.
    if ($route = $collection
      ->get('entity.taxonomy_term.delete_form')) {
      $route
        ->setRequirements([
        '_custom_access' => '\\vppr_route_access',
      ]);
    }

    // Reset order.
    if ($route = $collection
      ->get('entity.taxonomy_vocabulary.reset_form')) {
      $route
        ->setRequirements([
        '_custom_access' => '\\vppr_route_access',
      ]);
    }
    $route
      ->setOption('op', '');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RouteSubscriber::alterRoutes public function Alters existing routes for a specific collection. Overrides RouteSubscriberBase::alterRoutes
RouteSubscriberBase::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to. 5
RouteSubscriberBase::onAlterRoutes public function Delegates the route altering to self::alterRoutes(). 1