Suggestion.php in Search API Autocomplete 8
File
src/Suggestion/Suggestion.php
View source
<?php
namespace Drupal\search_api_autocomplete\Suggestion;
use Drupal\Core\Url;
class Suggestion implements SuggestionInterface {
protected $suggestedKeys;
protected $url;
protected $prefix;
protected $label;
protected $suggestionPrefix;
protected $userInput;
protected $suggestionSuffix;
protected $resultsCount;
protected $render;
public function __construct($suggested_keys = NULL, Url $url = NULL, $prefix = NULL, $label = NULL, $suggestion_prefix = NULL, $user_input = NULL, $suggestion_suffix = NULL, $results_count = NULL, array $render = NULL) {
$this->suggestedKeys = $suggested_keys;
$this->url = $url;
$this->prefix = $prefix;
$this->label = $label;
$this->suggestionPrefix = $suggestion_prefix;
$this->userInput = $user_input;
$this->suggestionSuffix = $suggestion_suffix;
$this->resultsCount = $results_count;
$this->render = $render;
}
public function getSuggestedKeys() {
if ($this->url) {
return NULL;
}
if ($this->suggestedKeys) {
return $this->suggestedKeys;
}
return $this->suggestionPrefix . $this->userInput . $this->suggestionSuffix;
}
public function getUrl() {
return $this->url;
}
public function getPrefix() {
return $this->prefix;
}
public function getLabel() {
return $this->label;
}
public function getSuggestionPrefix() {
return $this->suggestionPrefix;
}
public function getUserInput() {
return $this->userInput;
}
public function getSuggestionSuffix() {
return $this->suggestionSuffix;
}
public function getResultsCount() {
return $this->resultsCount;
}
public function getRender() {
return $this->render;
}
public function setSuggestedKeys($suggestedKeys) {
$this->suggestedKeys = $suggestedKeys;
return $this;
}
public function setUrl($url) {
$this->url = $url;
return $this;
}
public function setPrefix($prefix) {
$this->prefix = $prefix;
return $this;
}
public function setLabel($label) {
$this->label = $label;
return $this;
}
public function setSuggestionPrefix($suggestion_prefix) {
$this->suggestionPrefix = $suggestion_prefix;
return $this;
}
public function setUserInput($user_input) {
$this->userInput = $user_input;
return $this;
}
public function setSuggestionSuffix($suggestion_suffix) {
$this->suggestionSuffix = $suggestion_suffix;
return $this;
}
public function setResultsCount($results) {
$this->resultsCount = $results;
return $this;
}
public function setRender($render) {
$this->render = $render;
return $this;
}
public function toRenderable() {
if (!empty($this->render)) {
return $this->render;
}
return [
'#theme' => 'search_api_autocomplete_suggestion',
'#keys' => $this
->getSuggestedKeys(),
'#url' => $this
->getUrl(),
'#note' => $this
->getPrefix(),
'#label' => $this
->getLabel(),
'#results_count' => $this
->getResultsCount(),
'#suggestion_prefix' => $this
->getSuggestionPrefix(),
'#suggestion_suffix' => $this
->getSuggestionSuffix(),
'#user_input' => $this
->getUserInput(),
];
}
}
Classes
Name |
Description |
Suggestion |
Provides a value object meant to be used as result of suggestions. |