Loading src/Plugin/facets/facet_source/SearchApiDisplay.php +52 −14 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ namespace Drupal\facets\Plugin\facets\facet_source; use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Extension\ModuleHandler; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; Loading @@ -25,6 +26,13 @@ use Symfony\Component\HttpFoundation\Request; /** * Provides a facet source based on a Search API display. * * @todo The support for non views displays might be removed from facets 3.x and * moved into a sub or contributed module. So this class needs to become * something like "SearchApiViewsDisplay" and a "SearchApiCustomDisplay" * plugin needs to be provided by the sub or contributed module. At the * moment we have switches within this class for example to get the cache * metadata. Those need to be removed. * * @FacetsFacetSource( * id = "search_api", * deriver = "Drupal\facets\Plugin\facets\facet_source\SearchApiDisplayDeriver" Loading Loading @@ -430,34 +438,64 @@ class SearchApiDisplay extends FacetSourcePluginBase implements SearchApiFacetSo * {@inheritdoc} */ public function getCacheContexts() { return $this->getViewsDisplay() if ($views_display = $this->getViewsDisplay()) { return $views_display ->getDisplay() ->getCacheMetadata() ->getCacheContexts(); } // Custom display implementations should provide their own cache metadata. $display = $this->getDisplay(); if ($display instanceof CacheableDependencyInterface) { return $display->getCacheContexts(); } return []; } /** * {@inheritdoc} */ public function getCacheTags() { $view_display = $this->getViewsDisplay()->getDisplay(); if ($views_display = $this->getViewsDisplay()) { return Cache::mergeTags( $view_display->getCacheMetadata()->getCacheTags(), $this->getViewsDisplay()->getCacheTags() $views_display->getDisplay()->getCacheMetadata()->getCacheTags(), $views_display->getCacheTags() ); } // Custom display implementations should provide their own cache metadata. $display = $this->getDisplay(); if ($display instanceof CacheableDependencyInterface) { return $display->getCacheTags(); } return []; } /** * {@inheritdoc} */ public function getCacheMaxAge() { $view_display = $this->getViewsDisplay()->getDisplay(); if ($views_display = $this->getViewsDisplay()) { $cache_plugin = $views_display->getDisplay()->getPlugin('cache'); return Cache::mergeMaxAges( $view_display->getCacheMetadata()->getCacheMaxAge(), $view_display->getPlugin('cache')->getCacheMaxAge() $views_display->getDisplay()->getCacheMetadata()->getCacheMaxAge(), $cache_plugin ? $cache_plugin->getCacheMaxAge() : 0 ); } // Custom display implementations should provide their own cache metadata. $display = $this->getDisplay(); if ($display instanceof CacheableDependencyInterface) { return $display->getCacheMaxAge(); } // Caching is not supported. return 0; } /** * {@inheritDoc} * Loading Loading
src/Plugin/facets/facet_source/SearchApiDisplay.php +52 −14 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ namespace Drupal\facets\Plugin\facets\facet_source; use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Extension\ModuleHandler; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; Loading @@ -25,6 +26,13 @@ use Symfony\Component\HttpFoundation\Request; /** * Provides a facet source based on a Search API display. * * @todo The support for non views displays might be removed from facets 3.x and * moved into a sub or contributed module. So this class needs to become * something like "SearchApiViewsDisplay" and a "SearchApiCustomDisplay" * plugin needs to be provided by the sub or contributed module. At the * moment we have switches within this class for example to get the cache * metadata. Those need to be removed. * * @FacetsFacetSource( * id = "search_api", * deriver = "Drupal\facets\Plugin\facets\facet_source\SearchApiDisplayDeriver" Loading Loading @@ -430,34 +438,64 @@ class SearchApiDisplay extends FacetSourcePluginBase implements SearchApiFacetSo * {@inheritdoc} */ public function getCacheContexts() { return $this->getViewsDisplay() if ($views_display = $this->getViewsDisplay()) { return $views_display ->getDisplay() ->getCacheMetadata() ->getCacheContexts(); } // Custom display implementations should provide their own cache metadata. $display = $this->getDisplay(); if ($display instanceof CacheableDependencyInterface) { return $display->getCacheContexts(); } return []; } /** * {@inheritdoc} */ public function getCacheTags() { $view_display = $this->getViewsDisplay()->getDisplay(); if ($views_display = $this->getViewsDisplay()) { return Cache::mergeTags( $view_display->getCacheMetadata()->getCacheTags(), $this->getViewsDisplay()->getCacheTags() $views_display->getDisplay()->getCacheMetadata()->getCacheTags(), $views_display->getCacheTags() ); } // Custom display implementations should provide their own cache metadata. $display = $this->getDisplay(); if ($display instanceof CacheableDependencyInterface) { return $display->getCacheTags(); } return []; } /** * {@inheritdoc} */ public function getCacheMaxAge() { $view_display = $this->getViewsDisplay()->getDisplay(); if ($views_display = $this->getViewsDisplay()) { $cache_plugin = $views_display->getDisplay()->getPlugin('cache'); return Cache::mergeMaxAges( $view_display->getCacheMetadata()->getCacheMaxAge(), $view_display->getPlugin('cache')->getCacheMaxAge() $views_display->getDisplay()->getCacheMetadata()->getCacheMaxAge(), $cache_plugin ? $cache_plugin->getCacheMaxAge() : 0 ); } // Custom display implementations should provide their own cache metadata. $display = $this->getDisplay(); if ($display instanceof CacheableDependencyInterface) { return $display->getCacheMaxAge(); } // Caching is not supported. return 0; } /** * {@inheritDoc} * Loading