trait SearchApiHandlerTrait in Search API 8
Provides a trait to use for Search API Views handlers.
Hierarchy
- trait \Drupal\search_api\Plugin\views\SearchApiHandlerTrait
3 files declare their use of SearchApiHandlerTrait
- SearchApiDataRow.php in src/
Plugin/ views/ row/ SearchApiDataRow.php - SearchApiFieldTrait.php in src/
Plugin/ views/ field/ SearchApiFieldTrait.php - SearchApiFilterTrait.php in src/
Plugin/ views/ filter/ SearchApiFilterTrait.php
File
- src/
Plugin/ views/ SearchApiHandlerTrait.php, line 10
Namespace
Drupal\search_api\Plugin\viewsView source
trait SearchApiHandlerTrait {
/**
* Overrides the Views handlers' ensureMyTable() method.
*
* This is done since adding a table to a Search API query is neither
* necessary nor possible, but we still want to stay as compatible as possible
* to the default SQL query plugin.
*/
public function ensureMyTable() {
}
/**
* Determines the entity type used by this handler.
*
* If this handler uses a relationship, the base class of the relationship is
* taken into account.
*
* @return string
* The machine name of the entity type.
*
* @see \Drupal\views\Plugin\views\HandlerBase::getEntityType()
*/
public function getEntityType() {
return $this->definition['entity_type'] ?? parent::getEntityType();
}
/**
* Returns the active search index.
*
* @return \Drupal\search_api\IndexInterface|null
* The search index to use with this filter, or NULL if none could be
* loaded.
*/
protected function getIndex() {
if ($this
->getQuery()) {
return $this
->getQuery()
->getIndex();
}
$base_table = $this->view->storage
->get('base_table');
return SearchApiQuery::getIndexFromTable($base_table);
}
/**
* Retrieves the query plugin.
*
* @return \Drupal\search_api\Plugin\views\query\SearchApiQuery|null
* The query plugin, or NULL if there is no query or it is no Search API
* query.
*/
public function getQuery() {
$query = $this->query ?? $this->view->query ?? NULL;
return $query instanceof SearchApiQuery ? $query : NULL;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SearchApiHandlerTrait:: |
public | function | Overrides the Views handlers' ensureMyTable() method. | |
SearchApiHandlerTrait:: |
public | function | Determines the entity type used by this handler. | 1 |
SearchApiHandlerTrait:: |
protected | function | Returns the active search index. | |
SearchApiHandlerTrait:: |
public | function | Retrieves the query plugin. |