You are here

public function ElasticsearchViewsQuery::init in Elasticsearch Connector 8.5

Same name and namespace in other branches
  1. 8.7 modules/elasticsearch_connector_views/src/Plugin/views/query/ElasticsearchViewsQuery.php \Drupal\elasticsearch_connector_views\Plugin\views\query\ElasticsearchViewsQuery::init()
  2. 8.2 modules/elasticsearch_connector_views/src/Plugin/views/query/ElasticsearchViewsQuery.php \Drupal\elasticsearch_connector_views\Plugin\views\query\ElasticsearchViewsQuery::init()
  3. 8.6 modules/elasticsearch_connector_views/src/Plugin/views/query/ElasticsearchViewsQuery.php \Drupal\elasticsearch_connector_views\Plugin\views\query\ElasticsearchViewsQuery::init()

Initialize the plugin.

Parameters

\Drupal\views\ViewExecutable $view: The view object.

\Drupal\views\Plugin\views\display\DisplayPluginBase $display: The display handler.

array $options: The options configured for this plugin.

Overrides PluginBase::init

File

modules/elasticsearch_connector_views/src/Plugin/views/query/ElasticsearchViewsQuery.php, line 179

Class

ElasticsearchViewsQuery
Defines a Views query class for searching on Search API indexes.

Namespace

Drupal\elasticsearch_connector_views\Plugin\views\query

Code

public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
  try {
    parent::init($view, $display, $options);
    $view_id = $this->view->storage
      ->get('base_table');
    $data = Views::viewsData()
      ->get($view_id);
    $cluster_id = $data['table']['base']['cluster_id'];
    $this->index = $data['table']['base']['index'];
    $this->elasticsearchTypes[$data['table']['base']['type']] = $data['table']['base']['type'];
    $this->elasticsearchCluster = $this->entityTypeManager
      ->getStorage('elasticsearch_cluster')
      ->load($cluster_id);
    $clientManager = \Drupal::service('elasticsearch_connector.client_manager');
    $this->elasticsearchClient = $clientManager
      ->getClientForCluster($this->elasticsearchCluster);
  } catch (\Exception $e) {
    $this
      ->abort($e
      ->getMessage());
  }
}