You are here

public function SearchApiDisplay::getViewsDisplay in Facets 8

Retrieves the Views entity with the correct display set.

This returns NULL when the facet source is not based on views. If it is, it returns a ViewsExecutable plugin with the correct display already set.

Return value

\Drupal\views\ViewExecutable|null NULL when the view can't be found or loaded, the view with preset display otherwise.

Overrides SearchApiFacetSourceInterface::getViewsDisplay

1 call to SearchApiDisplay::getViewsDisplay()
SearchApiDisplay::buildFacet in src/Plugin/facets/facet_source/SearchApiDisplay.php
Builds and returns an extra renderable array for this facet block plugin.

File

src/Plugin/facets/facet_source/SearchApiDisplay.php, line 347

Class

SearchApiDisplay
Provides a facet source based on a Search API display.

Namespace

Drupal\facets\Plugin\facets\facet_source

Code

public function getViewsDisplay() {
  if (!$this->moduleHandler
    ->moduleExists('views')) {
    return NULL;
  }
  $search_api_display_definition = $this
    ->getDisplay()
    ->getPluginDefinition();
  if (empty($search_api_display_definition['view_id'])) {
    return NULL;
  }
  $view_id = $search_api_display_definition['view_id'];
  $view_display = $search_api_display_definition['view_display'];
  $view = Views::getView($view_id);
  $view
    ->setDisplay($view_display);
  return $view;
}