0

I have a requirement to limit the words to show up in row of autocomplete suggestion. Now its showing titles but problem is titles are too long and suggestions are covering entire width of the screen. So any way to limit it? I checked with HOOK_search_api_autocomplete_suggestions_alter hook but not getting what is the attribute to limit this feature. Any help will be appreciated.

0

Try below code, and you can trim $label as you want.

/**
 * Implements hook_search_api_autocomplete_suggestions_alter().
 */
function HOOK_search_api_autocomplete_suggestions_alter(array &$suggestions, array $alter_params) {
  $used_labels = [];
  /** @var Drupal\search_api_autocomplete\Suggestion\Suggestion[] $suggestions */
  foreach ($suggestions as $key => $suggestion) {
    $suggestion->setUrl(NULL);
    $label = $suggestion->getLabel();
    $suggestion->setSuggestedKeys($label);
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.