diff --git a/src/Plugin/facets/facet_source/SearchApiViews.php b/src/Plugin/facets/facet_source/SearchApiViews.php index 404c869..8372daf 100644 --- a/src/Plugin/facets/facet_source/SearchApiViews.php +++ b/src/Plugin/facets/facet_source/SearchApiViews.php @@ -16,7 +16,10 @@ use Drupal\views\Views; /** - * Represents a facet source which represents the search api views. + * A facet source to support search api views. + * + * This facet source only supports views that have a search api index as a base, + * and only those displays that are a block or a page. * * @FacetsFacetSource( * id = "search_api_views", diff --git a/src/Plugin/facets/facet_source/SearchApiViewsDeriver.php b/src/Plugin/facets/facet_source/SearchApiViewsDeriver.php index cdb1aab..0157fbc 100644 --- a/src/Plugin/facets/facet_source/SearchApiViewsDeriver.php +++ b/src/Plugin/facets/facet_source/SearchApiViewsDeriver.php @@ -13,6 +13,9 @@ use Drupal\facets\FacetSource\FacetSourceDeriverBase; /** * Derives a facet source plugin definition for every search api view. * + * This facet source only supports views that have a search api index as a base, + * and only those displays that are a block or a page. + * * @see \Drupal\facets\Plugin\facets\facet_source\SearchApiViews */ class SearchApiViewsDeriver extends FacetSourceDeriverBase { @@ -34,16 +37,27 @@ class SearchApiViewsDeriver extends FacetSourceDeriverBase { // Hardcoded usage of search api views, for now. if (strpos($view->get('base_table'), 'search_api_index') !== FALSE) { $displays = $view->get('display'); - foreach ($displays as $name => $display_info) { + foreach ($displays as $display_id => $display_info) { + + // We only support pages and blocks because those are the ones that + // we've tested. They are also the only ones that support for + // ::isRenderedInCurrentRequest() and ::getPath(). if (in_array($display_info['display_plugin'], ['page', 'block'])) { - $machine_name = $view->id() . PluginBase::DERIVATIVE_SEPARATOR . $name; + $machine_name = $view->id() . PluginBase::DERIVATIVE_SEPARATOR . $display_id; + $label_arguments = [ + '%view_name' => $view->label(), + '%display_title' => $display_info['display_title'], + '%display_type' => $display_info['display_plugin'], + ]; $plugin_derivatives[$machine_name] = [ 'id' => $base_plugin_id . PluginBase::DERIVATIVE_SEPARATOR . $machine_name, - 'label' => $this->t('Search api view: %view_name, display: %display_title', ['%view_name' => $view->label(), '%display_title' => $display_info['display_title']]), + 'label' => $this->t('Search api view: %view_name, display: %display_title (%display_type)', + $label_arguments + ), 'description' => $this->t('Provides a facet source.'), 'view_id' => $view->id(), - 'view_display' => $name, + 'view_display' => $display_id, ] + $base_plugin_definition; $sources[] = $this->t(