3 namespace Drupal\search\Form;
5 use Drupal\Core\Form\FormStateInterface;
8 * Provides a form for adding a search page.
10 class SearchPageAddForm extends SearchPageFormBase {
15 public function buildForm(array $form, FormStateInterface $form_state, $search_plugin_id = NULL) {
16 $this->entity->setPlugin($search_plugin_id);
17 $definition = $this->entity->getPlugin()->getPluginDefinition();
18 $this->entity->set('label', $definition['title']);
19 return parent::buildForm($form, $form_state);
25 protected function actions(array $form, FormStateInterface $form_state) {
26 $actions = parent::actions($form, $form_state);
27 $actions['submit']['#value'] = $this->t('Save');
34 public function save(array $form, FormStateInterface $form_state) {
35 // If there is no default search page, make the added search the default.
36 if (!$this->searchPageRepository->getDefaultSearchPage()) {
37 $this->searchPageRepository->setDefaultSearchPage($this->entity);
40 parent::save($form, $form_state);
42 drupal_set_message($this->t('The %label search page has been added.', ['%label' => $this->entity->label()]));