You are here

public function SearchBlock::blockForm in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/search/src/Plugin/Block/SearchBlock.php \Drupal\search\Plugin\Block\SearchBlock::blockForm()
  2. 10 core/modules/search/src/Plugin/Block/SearchBlock.php \Drupal\search\Plugin\Block\SearchBlock::blockForm()

Overrides BlockPluginTrait::blockForm

File

core/modules/search/src/Plugin/Block/SearchBlock.php, line 97

Class

SearchBlock
Provides a 'Search form' block.

Namespace

Drupal\search\Plugin\Block

Code

public function blockForm($form, FormStateInterface $form_state) {

  // The configuration for this block is which search page to connect the
  // form to. Options are all configured/active search pages.
  $options = [];
  $active_search_pages = $this->searchPageRepository
    ->getActiveSearchPages();
  foreach ($this->searchPageRepository
    ->sortSearchPages($active_search_pages) as $entity_id => $entity) {
    $options[$entity_id] = $entity
      ->label();
  }
  $form['page_id'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Search page'),
    '#description' => $this
      ->t('The search page that the form submits to, or Default for the default search page.'),
    '#default_value' => $this->configuration['page_id'],
    '#options' => $options,
    '#empty_option' => $this
      ->t('Default'),
    '#empty_value' => '',
  ];
  return $form;
}