You are here

public function SearchApiDisplay::buildFacet in Facets 8

Builds and returns an extra renderable array for this facet block plugin.

Return value

array A renderable array representing the content of the block.

Overrides FacetSourcePluginBase::buildFacet

See also

\Drupal\facets\Plugin\facets\facet_source\SearchApiDisplay

File

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

Class

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

Namespace

Drupal\facets\Plugin\facets\facet_source

Code

public function buildFacet() {
  $build = parent::buildFacet();
  $view = $this
    ->getViewsDisplay();
  if ($view === NULL) {
    return $build;
  }

  // Add JS for Views with Ajax Enabled.
  if ($view->display_handler
    ->ajaxEnabled()) {
    $js_settings = [
      'view_id' => $view
        ->id(),
      'current_display_id' => $view->current_display,
      'view_base_path' => ltrim($view
        ->getPath(), '/'),
      'ajax_path' => Url::fromRoute('views.ajax')
        ->toString(),
    ];
    $build['#attached']['library'][] = 'facets/drupal.facets.views-ajax';
    $build['#attached']['drupalSettings']['facets_views_ajax'] = [
      $this->facet
        ->id() => $js_settings,
    ];
    $build['#use_ajax'] = TRUE;
  }
  return $build;
}