function SearchPageAddForm::save

Same name and namespace in other branches
  1. 9 core/modules/search/src/Form/SearchPageAddForm.php \Drupal\search\Form\SearchPageAddForm::save()
  2. 8.9.x core/modules/search/src/Form/SearchPageAddForm.php \Drupal\search\Form\SearchPageAddForm::save()
  3. 10 core/modules/search/src/Form/SearchPageAddForm.php \Drupal\search\Form\SearchPageAddForm::save()

Overrides SearchPageFormBase::save

File

core/modules/search/src/Form/SearchPageAddForm.php, line 36

Class

SearchPageAddForm
Provides a form for adding a search page.

Namespace

Drupal\search\Form

Code

public function save(array $form, FormStateInterface $form_state) {
    // If there is no default search page, make the added search the default.
    // TRICKY: ::getDefaultSearchPage() will return the first active search page
    // as the default if no explicit default is configured in `search.settings`.
    // That's why this must be checked *before* saving the form.
    $make_default = !$this->searchPageRepository
        ->getDefaultSearchPage();
    parent::save($form, $form_state);
    if ($make_default) {
        $this->searchPageRepository
            ->setDefaultSearchPage($this->entity);
    }
    $this->messenger()
        ->addStatus($this->t('The %label search page has been added.', [
        '%label' => $this->entity
            ->label(),
    ]));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.