SU-SWS/stanford_fields

View on GitHub
src/Routing/StanfordFieldsRouteSubscriber.php

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
<?php

namespace Drupal\stanford_fields\Routing;

use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;

/**
 * Listens to the dynamic route events.
 */
class StanfordFieldsRouteSubscriber extends RouteSubscriberBase {

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {
    // Change path '/user/login' to '/login'.
    if ($route = $collection->get('book.admin_edit')) {
      $route->setDefault('_form', '\Drupal\stanford_fields\Form\StanfordFieldBookAdminEditForm');
    }

    if ($route = $collection->get('entity.node.book_outline_form')) {
      $route->setRequirement('_custom_access', 'book.manager:checkBookOutlineAccess');
    }
  }

}