You are here

protected function CoreViewsExposedFilter::loadFacetCoreViewsExposedFilterTypePlugin in Core Views Facets 8

Load the core_views_facet filter type or fall back to generic.

Parameters

\Drupal\views\Plugin\views\filter\FilterPluginBase $filter: The views filter handler.

Return value

\Drupal\core_views_facets\CoreViewsFacetsFilterTypeInterface The loaded filter type plugin or null.

Throws

\Drupal\Component\Plugin\Exception\PluginException If the instance cannot be created, such as if the ID is invalid.

1 call to CoreViewsExposedFilter::loadFacetCoreViewsExposedFilterTypePlugin()
CoreViewsExposedFilter::fillFacetsWithResults in src/Plugin/facets/facet_source/CoreViewsExposedFilter.php

File

src/Plugin/facets/facet_source/CoreViewsExposedFilter.php, line 266

Class

CoreViewsExposedFilter
Represents a facet source of the core views with exposed filters.

Namespace

Drupal\core_views_facets\Plugin\facets\facet_source

Code

protected function loadFacetCoreViewsExposedFilterTypePlugin(FilterPluginBase $filter) {
  $filter_type_definitions = $this->exposedFilterTypePluginManager
    ->getDefinitions();
  $custom_filter_id = $filter->view
    ->id() . '-' . $filter->field;

  // Allows to handle custom scenarios.
  if (!empty($filter_type_definitions[$custom_filter_id])) {

    /** @var \Drupal\core_views_facets\CoreViewsFacetsFilterTypeInterface $facet_core_views_filter_plugin */
    $facet_core_views_filter_plugin = $this->exposedFilterTypePluginManager
      ->createInstance($custom_filter_id);
  }
  elseif (!empty($filter_type_definitions[$filter->pluginId])) {

    /** @var \Drupal\core_views_facets\CoreViewsFacetsFilterTypeInterface $facet_core_views_filter_plugin */
    $facet_core_views_filter_plugin = $this->exposedFilterTypePluginManager
      ->createInstance($filter->pluginId);
  }
  else {

    /** @var \Drupal\core_views_facets\CoreViewsFacetsFilterTypeInterface $facet_core_views_filter_plugin */
    $facet_core_views_filter_plugin = $this->exposedFilterTypePluginManager
      ->createInstance('generic');
  }
  return $facet_core_views_filter_plugin;
}