/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#description' => $this->t('The label for this search page.'), '#default_value' => $this->entity->label(), '#maxlength' => '255'); $form['id'] = array('#type' => 'machine_name', '#default_value' => $this->entity->id(), '#disabled' => !$this->entity->isNew(), '#maxlength' => 64, '#machine_name' => array('exists' => array($this, 'exists'))); $form['path'] = array('#type' => 'textfield', '#title' => $this->t('Path'), '#field_prefix' => 'search/', '#default_value' => $this->entity->getPath(), '#maxlength' => '255', '#required' => TRUE); $form['plugin'] = array('#type' => 'value', '#value' => $this->entity->get('plugin')); if ($this->plugin instanceof PluginFormInterface) { $form += $this->plugin->buildConfigurationForm($form, $form_state); } return parent::form($form, $form_state); }
/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $plugin = $this->entity->getPlugin(); $form_state->set('search_page_id', $this->entity->id()); $form['basic'] = array('#type' => 'container', '#attributes' => array('class' => array('container-inline'))); $form['basic']['keys'] = array('#type' => 'search', '#title' => $this->t('Enter your keywords'), '#default_value' => $plugin->getKeywords(), '#size' => 30, '#maxlength' => 255); // processed_keys is used to coordinate keyword passing between other forms // that hook into the basic search form. $form['basic']['processed_keys'] = array('#type' => 'value', '#value' => ''); $form['basic']['submit'] = array('#type' => 'submit', '#value' => $this->t('Search')); // Allow the plugin to add to or alter the search form. $plugin->searchFormAlter($form, $form_state); return parent::form($form, $form_state); }
/** * Redirects to a search page. * * This is used to redirect from /search to the default search page. * * @param \Drupal\search\SearchPageInterface $entity * The search page entity. * * @return \Symfony\Component\HttpFoundation\RedirectResponse * A redirect to the search page. */ public function redirectSearchPage(SearchPageInterface $entity) { return $this->redirect('search.view_' . $entity->id()); }
/** * {@inheritdoc} */ public function setDefaultSearchPage(SearchPageInterface $search_page) { $this->configFactory->get('search.settings')->set('default_page', $search_page->id())->save(); $search_page->enable()->save(); }