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

Breadcrumb

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

function NodeSearch::buildConfigurationForm

Overrides PluginFormInterface::buildConfigurationForm

File

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

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' => $this->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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal