public function Database::buildConfigurationForm in Search API 8
Form constructor.
Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see \Drupal\Core\Render\Element\FormElement.
Parameters
array $form: An associative array containing the initial structure of the plugin form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().
Return value
array The form structure.
Overrides PluginFormInterface::buildConfigurationForm
File
- modules/
search_api_db/ src/ Plugin/ search_api/ backend/ Database.php, line 448
Class
- Database
- Indexes and searches items using the database.
Namespace
Drupal\search_api_db\Plugin\search_api\backendCode
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
// Discern between creation and editing of a server, since we don't allow
// the database to be changed later on.
if (!$this->configuration['database']) {
$options = [];
$key = $target = '';
foreach (CoreDatabase::getAllConnectionInfo() as $key => $targets) {
foreach ($targets as $target => $info) {
$options[$key]["{$key}:{$target}"] = "{$key} » {$target}";
}
}
if (count($options) > 1 || count(reset($options)) > 1) {
$form['database'] = [
'#type' => 'select',
'#title' => $this
->t('Database'),
'#description' => $this
->t('Select the database key and target to use for storing indexing information in. Cannot be changed after creation.'),
'#options' => $options,
'#default_value' => 'default:default',
'#required' => TRUE,
];
}
else {
$form['database'] = [
'#type' => 'value',
'#value' => "{$key}:{$target}",
];
}
}
else {
$form = [
'database' => [
'#type' => 'value',
'#title' => $this
->t('Database'),
'#value' => $this->configuration['database'],
],
'database_text' => [
'#type' => 'item',
'#title' => $this
->t('Database'),
'#plain_text' => str_replace(':', ' > ', $this->configuration['database']),
'#input' => FALSE,
],
];
}
$form['min_chars'] = [
'#type' => 'select',
'#title' => $this
->t('Minimum word length'),
'#description' => $this
->t('The minimum number of characters a word must consist of to be indexed'),
'#options' => array_combine([
1,
2,
3,
4,
5,
6,
], [
1,
2,
3,
4,
5,
6,
]),
'#default_value' => $this->configuration['min_chars'],
];
$form['matching'] = [
'#type' => 'radios',
'#title' => $this
->t('Partial matching'),
'#default_value' => $this->configuration['matching'],
'#options' => [
'words' => $this
->t('Match whole words only'),
'partial' => $this
->t('Match on parts of a word'),
'prefix' => $this
->t('Match words starting with given keywords'),
],
];
if ($this
->getModuleHandler()
->moduleExists('search_api_autocomplete')) {
$form['autocomplete'] = [
'#type' => 'details',
'#title' => $this
->t('Autocomplete settings'),
'#description' => $this
->t('These settings allow you to configure how suggestions are computed when autocompletion is used. If you are seeing many inappropriate suggestions you might want to deactivate the corresponding suggestion type. You can also deactivate one method to speed up the generation of suggestions.'),
];
$form['autocomplete']['suggest_suffix'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Suggest word endings'),
'#description' => $this
->t('Suggest endings for the currently entered word.'),
'#default_value' => $this->configuration['autocomplete']['suggest_suffix'],
];
$form['autocomplete']['suggest_words'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Suggest additional words'),
'#description' => $this
->t('Suggest additional words the user might want to search for.'),
'#default_value' => $this->configuration['autocomplete']['suggest_words'],
];
}
return $form;
}