You are here

public function NodeSearch::buildConfigurationForm in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/node/src/Plugin/Search/NodeSearch.php \Drupal\node\Plugin\Search\NodeSearch::buildConfigurationForm()
  2. 9 core/modules/node/src/Plugin/Search/NodeSearch.php \Drupal\node\Plugin\Search\NodeSearch::buildConfigurationForm()

File

core/modules/node/src/Plugin/Search/NodeSearch.php, line 822

Class

NodeSearch
Handles searching for node entities using the Search module index.

Namespace

Drupal\node\Plugin\Search

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {

  // Output form for defining rank factor weights.
  $form['content_ranking'] = [
    '#type' => 'details',
    '#title' => t('Content ranking'),
    '#open' => TRUE,
  ];
  $form['content_ranking']['info'] = [
    '#markup' => '<p><em>' . $this
      ->t('Influence is a numeric multiplier used in ordering search results. A higher number means the corresponding factor has more influence on search results; zero means the factor is ignored. Changing these numbers does not require the search index to be rebuilt. Changes take effect immediately.') . '</em></p>',
  ];

  // Prepare table.
  $header = [
    $this
      ->t('Factor'),
    $this
      ->t('Influence'),
  ];
  $form['content_ranking']['rankings'] = [
    '#type' => 'table',
    '#header' => $header,
  ];

  // Note: reversed to reflect that higher number = higher ranking.
  $range = range(0, 10);
  $options = array_combine($range, $range);
  foreach ($this
    ->getRankings() as $var => $values) {
    $form['content_ranking']['rankings'][$var]['name'] = [
      '#markup' => $values['title'],
    ];
    $form['content_ranking']['rankings'][$var]['value'] = [
      '#type' => 'select',
      '#options' => $options,
      '#attributes' => [
        'aria-label' => $this
          ->t("Influence of '@title'", [
          '@title' => $values['title'],
        ]),
      ],
      '#default_value' => $this->configuration['rankings'][$var] ?? 0,
    ];
  }
  return $form;
}