SearchPageAddForm.php in Drupal 9
File
core/modules/search/src/Form/SearchPageAddForm.php
View source
<?php
namespace Drupal\search\Form;
use Drupal\Core\Form\FormStateInterface;
class SearchPageAddForm extends SearchPageFormBase {
public function buildForm(array $form, FormStateInterface $form_state, $search_plugin_id = NULL) {
$this->entity
->setPlugin($search_plugin_id);
$definition = $this->entity
->getPlugin()
->getPluginDefinition();
$this->entity
->set('label', $definition['title']);
return parent::buildForm($form, $form_state);
}
protected function actions(array $form, FormStateInterface $form_state) {
$actions = parent::actions($form, $form_state);
$actions['submit']['#value'] = $this
->t('Save');
return $actions;
}
public function save(array $form, FormStateInterface $form_state) {
if (!$this->searchPageRepository
->getDefaultSearchPage()) {
$this->searchPageRepository
->setDefaultSearchPage($this->entity);
}
parent::save($form, $form_state);
$this
->messenger()
->addStatus($this
->t('The %label search page has been added.', [
'%label' => $this->entity
->label(),
]));
}
}