You are here

public function SearchExcludeNodeSearch::searchFormAlter in Search Exclude (Node) 8

Same name and namespace in other branches
  1. 2.x src/Plugin/Search/SearchExcludeNodeSearch.php \Drupal\search_exclude\Plugin\Search\SearchExcludeNodeSearch::searchFormAlter()
  2. 2.0.x src/Plugin/Search/SearchExcludeNodeSearch.php \Drupal\search_exclude\Plugin\Search\SearchExcludeNodeSearch::searchFormAlter()

Alters the search form when being built for a given plugin.

The core search module only invokes this method on active module plugins when building a form for them in \Drupal\search\Form\SearchPageForm::buildForm(). A plugin implementing this will also need to implement the buildSearchUrlQuery() method.

Parameters

array $form: Nested array of form elements that comprise the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. The arguments that \Drupal::formBuilder()->getForm() was originally called with are available in the array $form_state->getBuildInfo()['args'].

Overrides NodeSearch::searchFormAlter

See also

SearchInterface::buildSearchUrlQuery()

File

src/Plugin/Search/SearchExcludeNodeSearch.php, line 93

Class

SearchExcludeNodeSearch
Search plugin to exclude node bundles from the Search module index.

Namespace

Drupal\search_exclude\Plugin\Search

Code

public function searchFormAlter(array &$form, FormStateInterface $form_state) {
  parent::searchFormAlter($form, $form_state);

  // Remove excluded bundles from search form.
  $options = $form['advanced']['types-fieldset']['type']['#options'];
  $bundles = array_diff_key($options, $this->configuration['excluded_bundles']);
  $form['advanced']['types-fieldset']['type']['#options'] = $bundles;
}