492d6c0af734fdbcf87d73d5f665cdda47ae84ae
[yaffs-website] / web / core / modules / search / src / Form / SearchPageAddForm.php
1 <?php
2
3 namespace Drupal\search\Form;
4
5 use Drupal\Core\Form\FormStateInterface;
6
7 /**
8  * Provides a form for adding a search page.
9  *
10  * @internal
11  */
12 class SearchPageAddForm extends SearchPageFormBase {
13
14   /**
15    * {@inheritdoc}
16    */
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);
22   }
23
24   /**
25    * {@inheritdoc}
26    */
27   protected function actions(array $form, FormStateInterface $form_state) {
28     $actions = parent::actions($form, $form_state);
29     $actions['submit']['#value'] = $this->t('Save');
30     return $actions;
31   }
32
33   /**
34    * {@inheritdoc}
35    */
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);
40     }
41
42     parent::save($form, $form_state);
43
44     $this->messenger()->addStatus($this->t('The %label search page has been added.', ['%label' => $this->entity->label()]));
45   }
46
47 }