You are here

protected function RouteSubscriber::alterRoutes in Config Entity Revisions 8.2

Same name in this branch
  1. 8.2 modules/contact_form_revisions/src/Routing/RouteSubscriber.php \Drupal\contact_form_revisions\Routing\RouteSubscriber::alterRoutes()
  2. 8.2 modules/webform_revisions/src/Routing/RouteSubscriber.php \Drupal\webform_revisions\Routing\RouteSubscriber::alterRoutes()
  3. 8.2 modules/view_revisions/src/Routing/RouteSubscriber.php \Drupal\view_revisions\Routing\RouteSubscriber::alterRoutes()

Alters existing routes for a specific collection.

Parameters

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

Overrides RouteSubscriberBase::alterRoutes

File

modules/view_revisions/src/Routing/RouteSubscriber.php, line 18

Class

RouteSubscriber
Class RouteSubscriber.

Namespace

Drupal\view_revisions\Routing

Code

protected function alterRoutes(RouteCollection $collection) {
  $latest_revision_routes = [
    'entity.view.edit_form',
  ];
  foreach ($latest_revision_routes as $route_name) {
    if ($route = $collection
      ->get($route_name)) {
      $current = $route
        ->getOption('parameters') ?: [];
      $current['view']['load_latest_revision'] = TRUE;
      $route
        ->setOption('parameters', $current);
    }
  }

  // The following array should match the list in the RouteProcessor.
  $specific_revision_routes = [
    'entity.view.edit_display_form',
    'entity.view.preview_form',
    'views_ui.form_add_handler',
    'views_ui.form_edit_details',
    'views_ui.form_reorder_displays',
    'views_ui.form_analyze',
    'views_ui.form_rearrange',
    'views_ui.form_rearrange_filter',
    'views_ui.form_display',
    'views_ui.form_handler',
    'views_ui.form_handler_extra',
    'views_ui.form_handler_group',
  ];
  foreach ($specific_revision_routes as $route_name) {
    if ($route = $collection
      ->get($route_name)) {
      $current = $route
        ->getOption('parameters') ?: [];
      $current['revision_id'] = TRUE;
      $route
        ->setOption('parameters', $current);
      $path = $route
        ->getPath();
      $path = str_replace('{view}', '{view}/{revision_id}', $path);
      $route
        ->setPath($path);
    }
  }
  foreach ($collection as $route) {
    $options = $route
      ->getOptions();
    if (array_key_exists('_view_display_plugin_id', $options)) {
      $route
        ->setRequirement('_can_access_views_revision', 'TRUE');
    }
  }
}