You are here

public function SearchApiStatsBlock::blockForm in Search API Stats 8

Overrides BlockPluginTrait::blockForm

File

modules/search_api_stats_block/src/Plugin/Block/SearchApiStatsBlock.php, line 24

Class

SearchApiStatsBlock
Provides a 'SearchApiStatsBlock' block.

Namespace

Drupal\search_api_stats_block\Plugin\Block

Code

public function blockForm($form, FormStateInterface $form_state) {
  $numPhrases = range(2, 20);
  $numPhrases[] = 25;
  $numPhrases[] = 30;
  $form = parent::blockForm($form, $form_state);
  $config = $this
    ->getConfiguration();

  // Number of top search phrases to display.
  $form['num_phrases'] = [
    '#type' => 'select',
    '#title' => t('Number of top search phrases to display'),
    '#default_value' => empty($config['num_phrases']) ? 8 : $config['num_phrases'],
    '#options' => array_combine($numPhrases, $numPhrases),
  ];

  // Path of search page.
  $form['path'] = [
    '#type' => 'textfield',
    '#title' => t('Path of search page'),
    '#default_value' => empty($config['path']) ? 'search' : $config['path'],
  ];

  // Parameter name for the search phrase.
  $form['param_name'] = [
    '#type' => 'textfield',
    '#title' => t('Parameter name for the search phrase'),
    '#default_value' => empty($config['param_name']) ? 'search' : $config['param_name'],
  ];
  return $form;
}