d5bc7850ec76d4e8895fc033607665417ff29571
[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 class SearchPageAddForm extends SearchPageFormBase {
11
12   /**
13    * {@inheritdoc}
14    */
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);
20   }
21
22   /**
23    * {@inheritdoc}
24    */
25   protected function actions(array $form, FormStateInterface $form_state) {
26     $actions = parent::actions($form, $form_state);
27     $actions['submit']['#value'] = $this->t('Save');
28     return $actions;
29   }
30
31   /**
32    * {@inheritdoc}
33    */
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);
38     }
39
40     parent::save($form, $form_state);
41
42     drupal_set_message($this->t('The %label search page has been added.', ['%label' => $this->entity->label()]));
43   }
44
45 }