Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dashboards
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
dashboards
Merge requests
!2
Issue
#3205096
: Reset to default does not work
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Issue
#3205096
: Reset to default does not work
issue/dashboards-3205096:3205096-reset-to-default
into
8.x-1.x
Overview
0
Commits
4
Pipelines
0
Changes
1
Merged
Bram Driesen
requested to merge
issue/dashboards-3205096:3205096-reset-to-default
into
8.x-1.x
4 years ago
Overview
0
Commits
4
Pipelines
0
Changes
1
Expand
0
0
Merge request reports
Compare
8.x-1.x
version 3
b1ea2045
4 years ago
version 2
3dae65d3
4 years ago
version 1
9a179c57
4 years ago
8.x-1.x (base)
and
latest version
latest version
e6ca51cf
4 commits,
4 years ago
version 3
b1ea2045
3 commits,
4 years ago
version 2
3dae65d3
2 commits,
4 years ago
version 1
9a179c57
1 commit,
4 years ago
1 file
+
21
−
6
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
src/Form/DashboardLayoutBuilderForm.php
+
21
−
6
Options
@@ -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