Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. SearchBlock.php

function SearchBlock::blockForm

Overrides BlockPluginTrait::blockForm

File

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

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;
}
RSS feed
Powered by Drupal