You are here

public function RouteSubscriber::alterRoutes in Batch add terms 8

Alters existing routes for a specific collection.

Parameters

\Symfony\Component\Routing\RouteCollection $collection: The route collection for adding routes.

Overrides RouteSubscriberBase::alterRoutes

File

src/Routing/RouteSubscriber.php, line 18

Class

RouteSubscriber
Class for route alter.

Namespace

Drupal\batch_add_terms\Routing

Code

public function alterRoutes(RouteCollection $collection) {

  // Altering the access permissions as per vppr or taxonomy_access_fix.
  $moduleHandler = \Drupal::service('module_handler');

  // If vppr module enabled.
  if ($moduleHandler
    ->moduleExists('vppr')) {
    if ($route = $collection
      ->get('batch_add_terms.mass_add')) {
      $route
        ->setRequirements([
        '_custom_access' => '\\vppr_route_access',
      ]);
    }
    $route
      ->setOption('op', '');
  }

  // If taxonomy_access_fix module enabled.
  if ($moduleHandler
    ->moduleExists('taxonomy_access_fix')) {
    if ($route = $collection
      ->get('batch_add_terms.mass_add')) {
      $route
        ->setRequirements([
        '_custom_access' => '\\taxonomy_access_fix_route_access',
      ]);
      $route
        ->setOption('op', 'add terms');
    }
  }
}