Commit c97fb4fe authored by Hoi Sing Edison Wong's avatar Hoi Sing Edison Wong Committed by Markus Kalkbrenner
Browse files

Issue #2939710: Add support for "Search API (tags based)" caching in Views

parent 41f59dd5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@
  },
  "license": "GPL-2.0+",
  "require-dev": {
    "drupal/search_api": "~1.21",
    "drupal/search_api": "^1.24||1.x-dev",
    "drupal/jquery_ui_slider": "~1.1",
    "drupal/jquery_ui_touch_punch": "~1.0"
  },
+29 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
use Drupal\facets\Entity\Facet;
use Drupal\facets\Entity\FacetSource;
use Drupal\block\Entity\Block;
use Drupal\facets\Plugin\facets\facet_source\SearchApiDisplay;

/**
 * Implements hook_update_dependencies().
@@ -216,3 +217,31 @@ function facets_update_8009() {
    $facet->save();
  }
}

/**
 * Enable facet block caching for the views with "Search API tag or time" cache.
 */
function facets_update_8010() {
  $facet_storage = \Drupal::entityTypeManager()->getStorage('facets_facet');
  $processed_views = [];
  /** @var \Drupal\facets\FacetInterface $facet */
  foreach ($facet_storage->loadMultiple() as $facet) {
    if (
      ($source = $facet->getFacetSource())
      && $source instanceof SearchApiDisplay
      && ($view_executable = $source->getViewsDisplay())
      && !in_array($view_executable->id(), $processed_views)
      && ($cache_plugin = $view_executable->getDisplay()->getPlugin('cache'))
      && in_array(
        $cache_plugin->getPluginId(),
        ['search_api_tag', 'search_api_time']
      )
    ) {
      $view_executable->save();
      $processed_views[] = $view_executable->id();
    }
  }
  return !empty($processed_views)
    ? sprintf('Facet caching was enabled for the following views: %s.', implode(', ', $processed_views))
    : 'There are no views with search API cache plugins and facets in the same time, so nothing has been updated.';
}
+1 −3
Original line number Diff line number Diff line
@@ -292,9 +292,7 @@ class FacetsSummaryForm extends EntityForm {
    foreach ($processors_by_stage as $stage => $processors) {
      /** @var \Drupal\facets\Processor\ProcessorInterface $processor */
      foreach ($processors as $processor_id => $processor) {
        $weight = isset($processor_settings[$processor_id]['weights'][$stage])
          ? $processor_settings[$processor_id]['weights'][$stage]
          : $processor->getDefaultWeight($stage);
        $weight = $processor_settings[$processor_id]['weights'][$stage] ?? $processor->getDefaultWeight($stage);
        if ($processor->isHidden()) {
          $form['processors'][$processor_id]['weights'][$stage] = [
            '#type' => 'value',
+1 −1
Original line number Diff line number Diff line
@@ -234,7 +234,7 @@ class FacetsSummarySettingsForm extends EntityForm {
    // Clear Drupal cache for blocks to reflect recent changes.
    $this->blockManager->clearCachedDefinitions();
    $facet_source_id = $form_state->getValue('facet_source_id');
    list($type,) = explode(':', $facet_source_id);
    [$type] = explode(':', $facet_source_id);
    if ($type !== 'search_api') {
      return $facets_summary;
    }
+1 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ class FacetsSummaryBlockDeriver implements ContainerDeriverInterface {
   */
  public function getDerivativeDefinition($derivative_id, $base_plugin_definition) {
    $derivatives = $this->getDerivativeDefinitions($base_plugin_definition);
    return isset($derivatives[$derivative_id]) ? $derivatives[$derivative_id] : NULL;
    return $derivatives[$derivative_id] ?? NULL;
  }

  /**
Loading