class SuggestionManager in Linkit 8.5
Suggestion service to handle autocomplete suggestions.
Hierarchy
- class \Drupal\linkit\SuggestionManager uses StringTranslationTrait
Expanded class hierarchy of SuggestionManager
1 file declares its use of SuggestionManager
- AutocompleteController.php in src/
Controller/ AutocompleteController.php
1 string reference to 'SuggestionManager'
1 service uses SuggestionManager
File
- src/
SuggestionManager.php, line 13
Namespace
Drupal\linkitView source
class SuggestionManager {
use StringTranslationTrait;
/**
* Gets the suggestions.
*
* @param ProfileInterface $linkitProfile
* The linkit profile.
* @param string $search_string
* The string ro use in the matchers.
*
* @return \Drupal\linkit\Suggestion\SuggestionCollection
* A suggestion collection.
*/
public function getSuggestions(ProfileInterface $linkitProfile, $search_string) {
$suggestions = new SuggestionCollection();
if (empty(trim($search_string))) {
return $suggestions;
}
foreach ($linkitProfile
->getMatchers() as $plugin) {
$suggestions
->addSuggestions($plugin
->execute($search_string));
}
return $suggestions;
}
/**
* Adds an unscathed suggestion to the given suggestion collection.
*
* @param \Drupal\linkit\Suggestion\SuggestionCollection $suggestionCollection
* A suggestion collection to add the unscathed suggestion to.
* @param string $search_string
* The string ro use in the matchers.
*
* @return \Drupal\linkit\Suggestion\SuggestionCollection
* A suggestion collection.
*/
public function addUnscathedSuggestion(SuggestionCollection $suggestionCollection, $search_string) {
$suggestion = new DescriptionSuggestion();
$suggestion
->setLabel(Html::escape($search_string))
->setGroup($this
->t('No results'))
->setDescription($this
->t('No content suggestions found. This URL will be used as is.'))
->setPath($search_string);
$suggestionCollection
->addSuggestion($suggestion);
return $suggestionCollection;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
SuggestionManager:: |
public | function | Adds an unscathed suggestion to the given suggestion collection. | |
SuggestionManager:: |
public | function | Gets the suggestions. |