protected function SearchEditForm::getAvailableSuggesters in Search API Autocomplete 8
Returns all suggesters available for this search.
Return value
\Drupal\search_api_autocomplete\Suggester\SuggesterInterface[] The available suggesters, sorted by label.
3 calls to SearchEditForm::getAvailableSuggesters()
- SearchEditForm::buildSuggestersForm in src/
Form/ SearchEditForm.php - Builds a form for the search's suggester plugins.
- SearchEditForm::submitForm in src/
Form/ SearchEditForm.php - This is the default entity object builder function. It is called before any other submit handler to build the new entity object to be used by the following submit handlers. At this point of the form workflow the entity is validated and the form state…
- SearchEditForm::validateForm in src/
Form/ SearchEditForm.php - Form validation handler.
File
- src/
Form/ SearchEditForm.php, line 377
Class
- SearchEditForm
- Provides an edit form for autocomplete search entities.
Namespace
Drupal\search_api_autocomplete\FormCode
protected function getAvailableSuggesters() {
$suggesters = $this->entity
->getSuggesters();
$settings['#search'] = $this->entity;
$definitions = $this->suggesterManager
->getDefinitions();
foreach ($definitions as $plugin_id => $definition) {
if (isset($suggesters[$plugin_id])) {
continue;
}
if (class_exists($definition['class'])) {
$method = [
$definition['class'],
'supportsSearch',
];
if (call_user_func($method, $this->entity)) {
/** @var \Drupal\search_api_autocomplete\Suggester\SuggesterInterface $suggester */
$suggester = $this->suggesterManager
->createInstance($plugin_id, $settings);
$suggesters[$plugin_id] = $suggester;
}
}
else {
$this->logger
->warning('Suggester %id specifies a non-existing class %class.', [
'%id' => $plugin_id,
'%class' => $definition['class'],
]);
}
}
$compare = function (SuggesterInterface $a, SuggesterInterface $b) {
return strnatcasecmp($a
->label(), $b
->label());
};
uasort($suggesters, $compare);
return $suggesters;
}