/** * 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 an options list of available fulltext fields. * * @return string[] * An associative array mapping the identifiers of the index's fulltext * fields to their prefixed labels. */ protected function getFulltextFields() { $fields = array(); if (!empty($this->query)) { $index = $this->query->getIndex(); } else { $index = SearchApiQuery::getIndexFromTable($this->table); } if (!$index) { return array(); } $fields_info = $index->getFields(); foreach ($index->getFulltextFields() as $field_id) { $fields[$field_id] = $fields_info[$field_id]->getPrefixedLabel(); } return $fields; }
/** * {@inheritdoc} */ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { parent::init($view, $display, $options); $base_table = $view->storage->get('base_table'); $this->index = SearchApiQuery::getIndexFromTable($base_table, $this->getEntityManager()); if (!$this->index) { throw new \InvalidArgumentException(new FormattableMarkup('View %view is not based on Search API but tries to use its row plugin.', array('%view' => $view->storage->label()))); } }