class SearchPageAddForm
Same name and namespace in other branches
- 11.x core/modules/search/src/Form/SearchPageAddForm.php \Drupal\search\Form\SearchPageAddForm
Provides a form for adding a search page.
@internal
Hierarchy
- class \Drupal\Core\Form\FormBase extends \Drupal\Core\Form\FormInterface, \Drupal\Core\DependencyInjection\ContainerInjectionInterface uses \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Logger\LoggerChannelTrait, \Drupal\Core\Messenger\MessengerTrait, \Drupal\Core\Routing\RedirectDestinationTrait, \Drupal\Core\StringTranslation\StringTranslationTrait
- class \Drupal\Core\Entity\EntityForm extends \Drupal\Core\Entity\EntityFormInterface implements \Drupal\Core\Form\FormBase
- class \Drupal\search\Form\SearchPageFormBase implements \Drupal\Core\Entity\EntityForm
- class \Drupal\search\Form\SearchPageAddForm implements \Drupal\search\Form\SearchPageFormBase
- class \Drupal\search\Form\SearchPageFormBase implements \Drupal\Core\Entity\EntityForm
- class \Drupal\Core\Entity\EntityForm extends \Drupal\Core\Entity\EntityFormInterface implements \Drupal\Core\Form\FormBase
Expanded class hierarchy of SearchPageAddForm
File
-
core/
modules/ search/ src/ Form/ SearchPageAddForm.php, line 12
Namespace
Drupal\search\FormView source
class SearchPageAddForm extends SearchPageFormBase {
/**
* {@inheritdoc}
*/
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);
}
/**
* {@inheritdoc}
*/
protected function actions(array $form, FormStateInterface $form_state) {
$actions = parent::actions($form, $form_state);
$actions['submit']['#value'] = $this->t('Save');
return $actions;
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
// If there is no default search page, make the added search the default.
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(),
]));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.