Commit ce0fbe55 authored by borisson_'s avatar borisson_ Committed by borisson_

Issue #2859139 by borisson_, marcvangend, slasher13: Follow-up Automatically...

Issue #2859139 by borisson_, marcvangend, slasher13: Follow-up Automatically disable caching of views facet sources (regression)
parent 199477d3
......@@ -206,31 +206,6 @@ class FacetsSummarySettingsForm extends EntityForm {
$is_new = $facets_summary->isNew();
$facets_summary->save();
// Ensure that the caching of the view display is disabled, so the search
// correctly returns the facets. First, get the plugin definition of the
// Search API display.
$facet_source_id = $form_state->getValue('facet_source_id');
$facet_source = $this->facetSourcePluginManager->createInstance($facet_source_id, ['facet' => $this->getEntity()]);
if (isset($facet_source) && $facet_source instanceof FacetSourcePluginInterface) {
$facet_source_display_id = $facet_source->getPluginDefinition()['display_id'];
$search_api_display = \Drupal::service('plugin.manager.search_api.display')
->createInstance($facet_source_display_id);
$search_api_display_definition = $search_api_display->getPluginDefinition();
// Get the view of the Search API display and disable caching.
if (!empty($search_api_display_definition['view_id'])) {
$view_id = $search_api_display_definition['view_id'];
$view_display = $search_api_display_definition['view_display'];
$view = Views::getView($view_id);
$view->setDisplay($view_display);
$view->display_handler->overrideOption('cache', ['type' => 'none']);
$view->save();
drupal_set_message($this->t('Caching of view %view has been disabled.', ['%view' => $view->storage->label()]));
}
}
if ($is_new) {
if ($this->moduleHandler->moduleExists('block')) {
$message = $this->t('Facet Summary %name has been created. Go to the <a href=":block_overview">Block overview page</a> to place the new block in the desired region.', ['%name' => $facets_summary->getName(), ':block_overview' => $this->urlGenerator->generateFromRoute('block.admin_display')]);
......@@ -268,6 +243,35 @@ class FacetsSummarySettingsForm extends EntityForm {
// Clear Drupal cache for blocks to reflect recent changes.
$this->blockManager->clearCachedDefinitions();
if (!\Drupal::moduleHandler()->moduleExists('search_api')) {
return $facets_summary;
}
// Ensure that the caching of the view display is disabled, so the search
// correctly returns the facets. First, get the plugin definition of the
// Search API display.
$facet_source_id = $form_state->getValue('facet_source_id');
$facet_source = $this->facetSourcePluginManager->createInstance($facet_source_id, ['facet' => $this->getEntity()]);
if (isset($facet_source) && $facet_source instanceof FacetSourcePluginInterface) {
$facet_source_display_id = $facet_source->getPluginDefinition()['display_id'];
$search_api_display = \Drupal::service('plugin.manager.search_api.display')
->createInstance($facet_source_display_id);
$search_api_display_definition = $search_api_display->getPluginDefinition();
// Get the view of the Search API display and disable caching.
if (!empty($search_api_display_definition['view_id'])) {
$view_id = $search_api_display_definition['view_id'];
$view_display = $search_api_display_definition['view_display'];
$view = Views::getView($view_id);
$view->setDisplay($view_display);
$view->display_handler->overrideOption('cache', ['type' => 'none']);
$view->save();
drupal_set_message($this->t('Caching of view %view has been disabled.', ['%view' => $view->storage->label()]));
}
}
return $facets_summary;
}
......
......@@ -308,6 +308,28 @@ class FacetSettingsForm extends EntityForm {
}
$facet->save();
if ($is_new) {
if ($this->moduleHandler->moduleExists('block')) {
$message = $this->t('Facet %name has been created. Go to the <a href=":block_overview">Block overview page</a> to place the new block in the desired region.', ['%name' => $facet->getName(), ':block_overview' => $this->urlGenerator->generateFromRoute('block.admin_display')]);
drupal_set_message($message);
$form_state->setRedirect('entity.facets_facet.edit_form', ['facets_facet' => $facet->id()]);
}
if (isset($view_id, $display_plugin) && $display_plugin === 'block') {
$facet->setOnlyVisibleWhenFacetSourceIsVisible(FALSE);
}
}
else {
drupal_set_message($this->t('Facet %name has been updated.', ['%name' => $facet->getName()]));
}
// Clear Drupal cache for blocks to reflect recent changes.
$this->blockManager->clearCachedDefinitions();
if (!\Drupal::moduleHandler()->moduleExists('search_api')) {
return $facet;
}
// Ensure that the caching of the view display is disabled, so the search
// correctly returns the facets. First, get the plugin definition of the
// Search API display.
......@@ -328,29 +350,9 @@ class FacetSettingsForm extends EntityForm {
$view->save();
drupal_set_message($this->t('Caching of view %view has been disabled.', ['%view' => $view->storage->label()]));
$display_plugin = $view->getDisplay()->getPluginId();
}
}
if ($is_new) {
if ($this->moduleHandler->moduleExists('block')) {
$message = $this->t('Facet %name has been created. Go to the <a href=":block_overview">Block overview page</a> to place the new block in the desired region.', ['%name' => $facet->getName(), ':block_overview' => $this->urlGenerator->generateFromRoute('block.admin_display')]);
drupal_set_message($message);
$form_state->setRedirect('entity.facets_facet.edit_form', ['facets_facet' => $facet->id()]);
}
if (isset($view_id, $display_plugin) && $display_plugin === 'block') {
$facet->setOnlyVisibleWhenFacetSourceIsVisible(FALSE);
}
}
else {
drupal_set_message($this->t('Facet %name has been updated.', ['%name' => $facet->getName()]));
}
// Clear Drupal cache for blocks to reflect recent changes.
$this->blockManager->clearCachedDefinitions();
return $facet;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment