You are here

public function SuggestionFactory::createUrlSuggestion in Search API Autocomplete 8

Creates a suggestion that redirects to the specified URL.

Parameters

\Drupal\Core\Url $url: The URL to which this suggestion should redirect.

string|null $label: (optional) The label to set for the suggestion. Only makes sense if $render isn't given.

array|null $render: (optional) The render array that should be displayed for this suggestion.

Return value

\Drupal\search_api_autocomplete\Suggestion\SuggestionInterface An autocomplete suggestion.

File

src/Suggestion/SuggestionFactory.php, line 109

Class

SuggestionFactory
Provides factory methods for simpler creation of autocomplete suggestions.

Namespace

Drupal\search_api_autocomplete\Suggestion

Code

public function createUrlSuggestion(Url $url, $label = NULL, array $render = NULL) {
  $suggestion = new Suggestion(NULL, $url);
  if ($label !== NULL) {
    $suggestion
      ->setLabel($label);
  }
  if ($render !== NULL) {
    $suggestion
      ->setRender($render);
  }
  return $suggestion;
}