public function SearchApiElasticsearchBackend::buildConfigurationForm in Elasticsearch Connector 8.6
Same name and namespace in other branches
- 8.7 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::buildConfigurationForm()
- 8 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::buildConfigurationForm()
- 8.2 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::buildConfigurationForm()
- 8.5 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::buildConfigurationForm()
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
- src/
Plugin/ search_api/ backend/ SearchApiElasticsearchBackend.php, line 259
Class
- SearchApiElasticsearchBackend
- Elasticsearch Search API Backend definition.
Namespace
Drupal\elasticsearch_connector\Plugin\search_api\backendCode
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
if (!$this->server
->isNew()) {
$server_link = $this->cluster
->getSafeUrl();
// Editing this server.
$form['server_description'] = [
'#type' => 'item',
'#title' => $this
->t('Elasticsearch Cluster'),
'#description' => Link::fromTextAndUrl($server_link, Url::fromUri($server_link)),
];
}
$form['cluster_settings'] = [
'#type' => 'fieldset',
'#title' => t('Elasticsearch settings'),
];
// We are not displaying disabled clusters.
$clusters = $this->clusterManager
->loadAllClusters(FALSE);
$options = [];
foreach ($clusters as $key => $cluster) {
$options[$key] = $cluster->cluster_id;
}
$options[$this->clusterManager
->getDefaultCluster()] = t('Default cluster: @name', [
'@name' => $this->clusterManager
->getDefaultCluster(),
]);
$form['cluster_settings']['cluster'] = [
'#type' => 'select',
'#title' => t('Cluster'),
'#required' => TRUE,
'#options' => $options,
'#default_value' => $this->configuration['cluster_settings']['cluster'] ? $this->configuration['cluster_settings']['cluster'] : '',
'#description' => t('Select the cluster you want to handle the connections.'),
];
$fuzziness_options = [
'' => $this
->t('- Disabled -'),
self::FUZZINESS_AUTO => self::FUZZINESS_AUTO,
];
$fuzziness_options += array_combine(range(0, 5), range(0, 5));
$form['fuzziness'] = [
'#type' => 'select',
'#title' => t('Fuzziness'),
'#required' => TRUE,
'#options' => $fuzziness_options,
'#default_value' => $this->configuration['fuzziness'],
'#description' => $this
->t('Some queries and APIs support parameters to allow inexact fuzzy matching, using the fuzziness parameter. See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/5.6/common-options.html#fuzziness">Fuzziness</a> for more information.'),
];
return $form;
}