Skip to content
Snippets Groups Projects

Issue #3205096: Reset to default does not work

Merged Bram Driesen requested to merge issue/dashboards-3205096:3205096-reset-to-default into 8.x-1.x
@@ -2,7 +2,9 @@
namespace Drupal\dashboards\Form;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Routing\TrustedRedirectResponse;
use Drupal\Core\Url;
use Drupal\Core\Entity\EntityForm;
use Drupal\user\UserDataInterface;
@@ -128,20 +130,33 @@ class DashboardLayoutBuilderForm extends EntityForm {
* Form state.
*/
public function resetToDefault(array $form, FormStateInterface $form_state) {
/** @var \Drupal\dashboards\Entity\Dashboard $dashboard */
$dashboard = $this->sectionStorage->getContextValue(Dashboard::CONTEXT_TYPE);
// Delete the userdata containing the dashboard override.
$this->userData->delete(
'dashboards',
$this->account->id(),
$this->sectionStorage->getContextValue(Dashboard::CONTEXT_TYPE)->id()
$dashboard->id()
);
// Delete the tempstore so the override form is reloaded as well.
$this->layoutTempstoreRepository->delete($this->sectionStorage);
$form_state->setRedirectUrl(
Url::fromRoute('entity.dashboard.canonical', [
'dashboard' => $this->sectionStorage->getContextValue(Dashboard::CONTEXT_TYPE)->id(),
])
);
// Create a new trusted redirect response.
$response = new TrustedRedirectResponse(Url::fromRoute('entity.dashboard.canonical', [
'dashboard' => $dashboard->id(),
])->toString());
// Set cacheable metadata.
$metadata = $response->getCacheableMetadata();
$metadata->setCacheTags($dashboard->getCacheTags());
$metadata->setCacheContexts($dashboard->getCacheContexts());
// Also invalidate the cache.
Cache::invalidateTags($dashboard->getCacheTags());
// Set the response so we're redirected back to the dashboard.
$form_state->setResponse($response);
}
/**
Loading