3 namespace Drupal\search\Routing;
5 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
6 use Drupal\search\SearchPageRepositoryInterface;
7 use Symfony\Component\DependencyInjection\ContainerInterface;
8 use Symfony\Component\Routing\Route;
11 * Provides dynamic routes for search.
13 class SearchPageRoutes implements ContainerInjectionInterface {
16 * The search page repository.
18 * @var \Drupal\search\SearchPageRepositoryInterface
20 protected $searchPageRepository;
23 * Constructs a new search route subscriber.
25 * @param \Drupal\search\SearchPageRepositoryInterface $search_page_repository
26 * The search page repository.
28 public function __construct(SearchPageRepositoryInterface $search_page_repository) {
29 $this->searchPageRepository = $search_page_repository;
35 public static function create(ContainerInterface $container) {
37 $container->get('search.search_page_repository')
42 * Returns an array of route objects.
44 * @return \Symfony\Component\Routing\Route[]
45 * An array of route objects.
47 public function routes() {
49 // @todo Decide if /search should continue to redirect to /search/$default,
50 // or just perform the appropriate search.
51 if ($default_page = $this->searchPageRepository->getDefaultSearchPage()) {
52 $routes['search.view'] = new Route(
55 '_controller' => 'Drupal\search\Controller\SearchController::redirectSearchPage',
57 'entity' => $default_page,
60 '_entity_access' => 'entity.view',
61 '_permission' => 'search content',
66 'type' => 'entity:search_page',
72 $active_pages = $this->searchPageRepository->getActiveSearchPages();
73 foreach ($active_pages as $entity_id => $entity) {
74 $routes["search.view_$entity_id"] = new Route(
75 '/search/' . $entity->getPath(),
77 '_controller' => 'Drupal\search\Controller\SearchController::view',
79 'entity' => $entity_id,
82 '_entity_access' => 'entity.view',
83 '_permission' => 'search content',
88 'type' => 'entity:search_page',
94 $routes["search.help_$entity_id"] = new Route(
95 '/search/' . $entity->getPath() . '/help',
97 '_controller' => 'Drupal\search\Controller\SearchController::searchHelp',
98 '_title' => 'Search help',
99 'entity' => $entity_id,
102 '_entity_access' => 'entity.view',
103 '_permission' => 'search content',
108 'type' => 'entity:search_page',