You are here

public function SearchPageRoutes::routes in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/search/src/Routing/SearchPageRoutes.php \Drupal\search\Routing\SearchPageRoutes::routes()

Returns an array of route objects.

Return value

\Symfony\Component\Routing\Route[] An array of route objects.

1 string reference to 'SearchPageRoutes::routes'
search.routing.yml in core/modules/search/search.routing.yml
core/modules/search/search.routing.yml

File

core/modules/search/src/Routing/SearchPageRoutes.php, line 47

Class

SearchPageRoutes
Provides dynamic routes for search.

Namespace

Drupal\search\Routing

Code

public function routes() {
  $routes = [];

  // @todo Decide if /search should continue to redirect to /search/$default,
  //   or just perform the appropriate search.
  if ($default_page = $this->searchPageRepository
    ->getDefaultSearchPage()) {
    $routes['search.view'] = new Route('/search', [
      '_controller' => 'Drupal\\search\\Controller\\SearchController::redirectSearchPage',
      '_title' => 'Search',
      'entity' => $default_page,
    ], [
      '_entity_access' => 'entity.view',
      '_permission' => 'search content',
    ], [
      'parameters' => [
        'entity' => [
          'type' => 'entity:search_page',
        ],
      ],
    ]);
  }
  $active_pages = $this->searchPageRepository
    ->getActiveSearchPages();
  foreach ($active_pages as $entity_id => $entity) {
    $routes["search.view_{$entity_id}"] = new Route('/search/' . $entity
      ->getPath(), [
      '_controller' => 'Drupal\\search\\Controller\\SearchController::view',
      '_title' => 'Search',
      'entity' => $entity_id,
    ], [
      '_entity_access' => 'entity.view',
      '_permission' => 'search content',
    ], [
      'parameters' => [
        'entity' => [
          'type' => 'entity:search_page',
        ],
      ],
    ]);
    $routes["search.help_{$entity_id}"] = new Route('/search/' . $entity
      ->getPath() . '/help', [
      '_controller' => 'Drupal\\search\\Controller\\SearchController::searchHelp',
      '_title' => 'Search help',
      'entity' => $entity_id,
    ], [
      '_entity_access' => 'entity.view',
      '_permission' => 'search content',
    ], [
      'parameters' => [
        'entity' => [
          'type' => 'entity:search_page',
        ],
      ],
    ]);
  }
  return $routes;
}