You are here

public function RouteSubscriber::alterRoutes in Google Site Search 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 17

Class

RouteSubscriber
Listens to the dynamic route events.

Namespace

Drupal\gss\Routing

Code

public function alterRoutes(RouteCollection $collection) {

  // Alter search page controller for this module's plugin.

  /** @var \Drupal\search\SearchPageRepositoryInterface $searchPageRepository */
  $searchPageRepository = \Drupal::service('search.search_page_repository');
  foreach ($searchPageRepository
    ->getActiveSearchPages() as $entity_id => $entity) {
    if ($entity
      ->getPlugin() instanceof GssSearch && ($route = $collection
      ->get("search.view_{$entity_id}"))) {
      $route
        ->setDefault('_controller', 'Drupal\\gss\\Controller\\GssSearchController::view');
    }
  }
}