public function Suggester::buildConfigurationForm in Search API Solr 8.2
Same name and namespace in other branches
- 8.3 src/Plugin/search_api_autocomplete/suggester/Suggester.php \Drupal\search_api_solr\Plugin\search_api_autocomplete\suggester\Suggester::buildConfigurationForm()
- 4.x src/Plugin/search_api_autocomplete/suggester/Suggester.php \Drupal\search_api_solr\Plugin\search_api_autocomplete\suggester\Suggester::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_autocomplete/ suggester/ Suggester.php, line 54
Class
- Suggester
- Provides a suggester plugin that retrieves suggestions from the server.
Namespace
Drupal\search_api_solr\Plugin\search_api_autocomplete\suggesterCode
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$search = $this
->getSearch();
$server = $search
->getIndex()
->getServerInstance();
$form['search_api_solr/site_hash'] = [
'#type' => 'checkbox',
'#title' => $this
->t('From this site only'),
'#description' => $this
->t('Limit the suggestion dictionary to entries created by this site in case of a multisite setup.'),
'#default_value' => $this
->getConfiguration()['search_api_solr/site_hash'],
];
$index_options['any'] = $this
->t('Any index');
foreach ($server
->getIndexes() as $index) {
$index_options[$index
->id()] = $this
->t('Index @index', [
'@index' => $index
->label(),
]);
}
$form['search_api/index'] = [
'#type' => 'radios',
'#title' => $this
->t('Index'),
'#description' => $this
->t('Limit the suggestion dictionary to entries to those created by a specific index.'),
'#options' => $index_options,
'#default_value' => $this
->getConfiguration()['search_api/index'] ?: $search
->getIndex()
->id(),
];
$langcode_options['any'] = $this
->t('Any language');
if ($server
->getBackend() instanceof SolrMultilingualBackendInterface) {
$langcode_options['multilingual'] = $this
->t('Let the multilingual Solr server handle it dynamically.');
}
foreach (\Drupal::languageManager()
->getLanguages() as $language) {
$langcode_options[$language
->getId()] = $language
->getName();
}
$langcode_options['und'] = $this
->t('Undefined');
$form['drupal/langcode'] = [
'#type' => 'radios',
'#title' => $this
->t('Language'),
'#description' => $this
->t('Limit the suggestion dictionary to entries that belong to a specific language.'),
'#options' => $langcode_options,
'#default_value' => $this
->getConfiguration()['drupal/langcode'],
];
return $form;
}