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