Page.php in Search API Autocomplete 8
File
src/Plugin/search_api_autocomplete/search/Page.php
View source
<?php
namespace Drupal\search_api_autocomplete\Plugin\search_api_autocomplete\search;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\search_api\Utility\QueryHelperInterface;
use Drupal\search_api_autocomplete\Search\SearchPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Page extends SearchPluginBase implements ContainerFactoryPluginInterface {
protected $entityTypeManager;
protected $queryHelper;
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$plugin = new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'));
$plugin
->setQueryHelper($container
->get('search_api.query_helper'));
return $plugin;
}
public function getQueryHelper() {
return $this->queryHelper ?: \Drupal::service('search_api.query_helper');
}
public function setQueryHelper(QueryHelperInterface $query_helper) {
$this->queryHelper = $query_helper;
return $this;
}
public function createQuery($keys, array $data = []) {
$query = $this
->getQueryHelper()
->createQuery($this
->getIndex());
$query
->keys($keys);
$page = $this
->getPage();
if ($page && $page
->getSearchedFields()) {
$query
->setFulltextFields(array_values($page
->getSearchedFields()));
}
return $query;
}
protected function getPage() {
$page = $this
->getEntityTypeManager()
->getStorage('search_api_page')
->load($this
->getDerivativeId());
return $page;
}
public function calculateDependencies() {
$this->dependencies = parent::calculateDependencies();
$page = $this
->getPage();
if ($page) {
$key = $page
->getConfigDependencyKey();
$name = $page
->getConfigDependencyName();
$this
->addDependency($key, $name);
}
return $this->dependencies;
}
}
Classes
Name |
Description |
Page |
Provides autocomplete support for the search_api_page module. |