function SearchPageListBuilder::buildForm
Same name in other branches
- 9 core/modules/search/src/SearchPageListBuilder.php \Drupal\search\SearchPageListBuilder::buildForm()
- 8.9.x core/modules/search/src/SearchPageListBuilder.php \Drupal\search\SearchPageListBuilder::buildForm()
- 11.x core/modules/search/src/SearchPageListBuilder.php \Drupal\search\SearchPageListBuilder::buildForm()
Overrides DraggableListBuilderTrait::buildForm
File
-
core/
modules/ search/ src/ SearchPageListBuilder.php, line 184
Class
- SearchPageListBuilder
- Defines a class to build a listing of search page entities.
Namespace
Drupal\searchCode
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$search_settings = $this->config('search.settings');
// Collect some stats.
$remaining = 0;
$total = 0;
foreach ($this->entities as $entity) {
if ($entity->isIndexable() && ($status = $entity->getPlugin()
->indexStatus())) {
$remaining += $status['remaining'];
$total += $status['total'];
}
}
$this->moduleHandler
->loadAllIncludes('admin.inc');
$count = $this->formatPlural($remaining, 'There is 1 item left to index.', 'There are @count items left to index.');
$done = $total - $remaining;
// Use floor() to calculate the percentage, so if it is not quite 100%, it
// will show as 99%, to indicate "almost done".
$percentage = $total > 0 ? floor(100 * $done / $total) : 100;
$percentage .= '%';
$status = '<p><strong>' . $this->t('%percentage of the site has been indexed.', [
'%percentage' => $percentage,
]) . ' ' . $count . '</strong></p>';
$form['status'] = [
'#type' => 'details',
'#title' => $this->t('Indexing progress'),
'#open' => TRUE,
'#description' => $this->t('Only items in the index will appear in search results. To build and maintain the index, a correctly configured <a href=":cron">cron maintenance task</a> is required.', [
':cron' => Url::fromRoute('system.cron_settings')->toString(),
]),
];
$form['status']['status'] = [
'#markup' => $status,
];
$form['status']['wipe'] = [
'#type' => 'submit',
'#value' => $this->t('Re-index site'),
'#submit' => [
'::searchAdminReindexSubmit',
],
];
$items = [
10,
20,
50,
100,
200,
500,
];
$items = array_combine($items, $items);
// Indexing throttle:
$form['indexing_throttle'] = [
'#type' => 'details',
'#title' => $this->t('Indexing throttle'),
'#open' => TRUE,
];
$form['indexing_throttle']['cron_limit'] = [
'#type' => 'select',
'#title' => $this->t('Number of items to index per run'),
'#default_value' => $search_settings->get('index.cron_limit'),
'#options' => $items,
'#description' => $this->t('The maximum number of items processed per indexing run. If necessary, reduce the number of items to prevent timeouts and memory errors while indexing. Some search page types may have their own setting for this.'),
];
// Indexing settings:
$form['indexing_settings'] = [
'#type' => 'details',
'#title' => $this->t('Default indexing settings'),
'#open' => TRUE,
'#description' => $this->t('Changing these settings will cause the default search index to be rebuilt to reflect the new settings. Searching will continue to work, based on the existing index, but new content will not be indexed until all existing content has been re-indexed.'),
];
$form['indexing_settings']['minimum_word_size'] = [
'#type' => 'number',
'#title' => $this->t('Minimum word length to index'),
'#default_value' => $search_settings->get('index.minimum_word_size'),
'#min' => 1,
'#max' => 1000,
'#description' => $this->t('The minimum character length for a word to be added to the index. Searches must include a keyword of at least this length.'),
];
$form['indexing_settings']['overlap_cjk'] = [
'#type' => 'checkbox',
'#title' => $this->t('Simple CJK handling'),
'#default_value' => $search_settings->get('index.overlap_cjk'),
'#description' => $this->t('Whether to apply a simple Chinese/Japanese/Korean tokenizer based on overlapping sequences. Turn this off if you want to use an external preprocessor for this instead. Does not affect other languages.'),
];
// Indexing settings:
$form['logging'] = [
'#type' => 'details',
'#title' => $this->t('Logging'),
'#open' => TRUE,
];
$form['logging']['logging'] = [
'#type' => 'checkbox',
'#title' => $this->t('Log searches'),
'#default_value' => $search_settings->get('logging'),
'#description' => $this->t('If checked, all searches will be logged. Uncheck to skip logging. Logging may affect performance.'),
];
$form['search_pages'] = [
'#type' => 'details',
'#title' => $this->t('Search pages'),
'#open' => TRUE,
];
$form['search_pages']['add_page'] = [
'#type' => 'container',
'#attributes' => [
'class' => [
'container-inline',
],
],
];
// In order to prevent validation errors for the parent form, this cannot be
// required, see self::validateAddSearchPage().
$form['search_pages']['add_page']['search_type'] = [
'#type' => 'select',
'#title' => $this->t('Search page type'),
'#empty_option' => $this->t('- Choose page type -'),
'#options' => array_map(function ($definition) {
return $definition['title'];
}, $this->searchManager
->getDefinitions()),
];
$form['search_pages']['add_page']['add_search_submit'] = [
'#type' => 'submit',
'#value' => $this->t('Add search page'),
'#validate' => [
'::validateAddSearchPage',
],
'#submit' => [
'::submitAddSearchPage',
],
'#limit_validation_errors' => [
[
'search_type',
],
],
];
// Move the listing into the search_pages element.
$form['search_pages'][$this->entitiesKey] = $form[$this->entitiesKey];
$form['search_pages'][$this->entitiesKey]['#empty'] = $this->t('No search pages have been configured.');
unset($form[$this->entitiesKey]);
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Save configuration'),
'#button_type' => 'primary',
];
return $form;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.