/**
  * {@inheritdoc}
  */
 public function getDerivativeDefinitions($base_plugin_definition)
 {
     $this->derivatives = array();
     if ($default = $this->searchPageRepository->getDefaultSearchPage()) {
         $active_search_pages = $this->searchPageRepository->getActiveSearchPages();
         foreach ($this->searchPageRepository->sortSearchPages($active_search_pages) as $entity_id => $entity) {
             $this->derivatives[$entity_id] = array('title' => $entity->label(), 'route_name' => 'search.view_' . $entity_id, 'base_route' => 'search.plugins:' . $default, 'weight' => $entity->getWeight());
         }
     }
     return $this->derivatives;
 }
 /**
  * Returns an array of route objects.
  *
  * @return \Symfony\Component\Routing\Route[]
  *   An array of route objects.
  */
 public function routes()
 {
     $routes = array();
     // @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', array('_content' => 'Drupal\\search\\Controller\\SearchController::redirectSearchPage', '_title' => 'Search', 'entity' => $default_page), array('_entity_access' => 'entity.view', '_permission' => 'search content'), array('parameters' => array('entity' => array('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(), array('_content' => 'Drupal\\search\\Controller\\SearchController::view', '_title' => 'Search', 'entity' => $entity_id), array('_entity_access' => 'entity.view', '_permission' => 'search content'), array('parameters' => array('entity' => array('type' => 'entity:search_page'))));
     }
     return $routes;
 }
Beispiel #3
0
 /**
  * Sets the search page as the default.
  *
  * @param \Drupal\search\SearchPageInterface $search_page
  *   The search page entity.
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  *   A redirect to the search settings page.
  */
 public function setAsDefault(SearchPageInterface $search_page)
 {
     // Set the default page to this search page.
     $this->searchPageRepository->setDefaultSearchPage($search_page);
     drupal_set_message($this->t('The default search page is now %label. Be sure to check the ordering of your search pages.', array('%label' => $search_page->label())));
     return $this->redirect('search.settings');
 }
Beispiel #4
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, array &$form_state)
 {
     // Set up the form to submit using GET to the correct search page.
     $entity_id = $this->searchPageRepository->getDefaultSearchPage();
     if (!$entity_id) {
         $form['message'] = array('#markup' => $this->t('Search is currently disabled'));
         return $form;
     }
     $route = 'search.view_' . $entity_id;
     $form['#action'] = $this->url($route);
     $form['#token'] = FALSE;
     $form['#method'] = 'get';
     $form['keys'] = array('#type' => 'search', '#title' => $this->t('Search'), '#title_display' => 'invisible', '#size' => 15, '#default_value' => '', '#attributes' => array('title' => $this->t('Enter the terms you wish to search for.')));
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Search'), '#name' => '');
     return $form;
 }
Beispiel #5
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     // Set up the form to submit using GET to the correct search page.
     $entity_id = $this->searchPageRepository->getDefaultSearchPage();
     if (!$entity_id) {
         $form['message'] = array('#markup' => $this->t('Search is currently disabled'));
         return $form;
     }
     $route = 'search.view_' . $entity_id;
     $form['#action'] = $this->url($route);
     $form['#method'] = 'get';
     $form['keys'] = array('#type' => 'search', '#title' => $this->t('Search'), '#title_display' => 'invisible', '#size' => 15, '#default_value' => '', '#attributes' => array('title' => $this->t('Enter the terms you wish to search for.')));
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Search'), '#name' => '');
     // SearchPageRepository::getDefaultSearchPage() depends on search.settings.
     $this->renderer->addCacheableDependency($form, $this->configFactory->get('search.settings'));
     return $form;
 }