Problem/Motivation
As part of the Dashboard initiative #3244581: Enhance user experience with customizable dashboards one of the needs detected was the ability to clear caches from the dashboard for admin users.
Would be great to have a block in the admin dashboard for clearing caches to make it more simple and intuitive for admin users..
Proposed resolution
As the dashboard concept is developed, provide the ability to clear caches form a block on the dashboard.
Remaining tasks
Product manager review
User interface changes
New block available. See screenshot: 
API changes
None.
Data model changes
None.

| Comment | File | Size | Author |
|---|---|---|---|
| #50 | 3351706-50-suggestion.png | 82.29 KB | nikhil_110 |
| #50 | Before-patch-3351706-50.png | 247.38 KB | nikhil_110 |
| #50 | After-patch-3351706-50-1.png | 280.6 KB | nikhil_110 |
| #50 | After-patch-3351706-50-2.png | 164.4 KB | nikhil_110 |
| #50 | 3351706-50-suggestion.png | 82.29 KB | nikhil_110 |
Issue fork drupal-3351706
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Issue fork 3327580-3351706
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3351706-Add-block
changes, plain diff MR !6
Comments
Comment #4
penyaskitoThis needs to be worked on as a patch and not a MR, as this against core.
Comment #5
elbersorry I will try to work on it.
Comment #6
penyaskitoSorry I confused this with a different issue. Please feel free to work on this.
However, it needs to be a patch and not a MR, as this would be a patch against core and not against this sandbox module.
Comment #7
penyaskito@elber You are definitely welcome to work on this. Really sorry if I looked annoyed, edited the previous comments.
Comment #8
gxleano commentedI will take this issue as it has not had any feedback for a month.
Comment #9
gxleano commentedAttached patch against core.
Comment #10
gxleano commentedComment #11
elberI will review it.
Comment #12
elberHi I took a look on it.
Patch is good
Issue problem was fixed
route is also ok
Moving to RTBC
Comment #13
plopescHi!
Thank you for the patch.
Checked the code and I think that could be better to have an actual form instead of a link to clear the cache. In this way, we are exposing a URL to clear the cache remotely and that's not desirable, I think.
This is mitigated by the fact of the permission necessary to access to hat URL, but I think that a form is a better solution, like in
/admin/config/development/performance.Reusing
Drupal\system\Form\ClearCacheFormcould be a possibility as well.Comment #14
gxleano commentedThanks @plopesc for the feedback!
I will work on this new form.
Comment #15
gxleano commentedComment #16
penyaskitoI've spent 2 hours debugging this but I cannot place this block. It just doesn't appear as an option nor in a dashboard nor in the general blocks page.
I've reviewed the code and didn't find anything wrong.
Comment #17
penyaskitoOh the patch failed to apply and somehow didn't notice.
Comment #18
penyaskitoSolved the patching issue with -p2: https://github.com/penyaskito/dashboard-initiative/commit/6e3d13508f80bb...
The Clear cache form includes a collapsible details elements that make the dashboard look weird.
I think we should refactor the performance page controller so the details is out of the form itself.
We want to do the same on PerformanceForm for consistency.
Comment #19
penyaskitoAttached screenshot for clarity
Comment #20
gxleano commentedThanks @penyaskito for the fix!
As for the Cache block, I had the same feeling when I was working on this. So, I'm going to spend some time to refactor the performance page controller.
Comment #21
gxleano commentedI have been checking the
ClearCacheFormclass in order to try to refactor the details element to get ride off it, but on my eyes this would be a "big" change in the look and feel of the config in Drupal.The most of the config pages in Drupal are using this collapsible details element, also in the performance page, the performance form is using it, we could try to find a good alternative to change it only in the performance page, but I would say it should follow the same look and feel than the rest of the config pages in Drupal, so in this case I would try with two possible options here:
1. Create a new Clear cache form only with the submit button (I don't really like this option as we would be doing the same thing twice in a different way)
2. In the new Clear cache block which we are providing, once we get the Clear cache form in the build method, get ride off the details element.
Comment #22
plopescHi @gxleano
We could explore a 3rd option:
Comment #23
penyaskito@plopesc proposal is what I tried to explain at #18, but he does better than me.
I'm fine with #17.2 if it works, and we can improve that when this is merged in core as a follow-up as a path to stable. Did you forget to attach the patch?
Comment #24
gxleano commentedI like the option that @plopesc mention in #22, so I will attach the patch with this solution during the day.
Thanks to both!!
Comment #25
gxleano commentedComment #26
gxleano commentedComment #27
gxleano commentedFix patch #25
Comment #28
gxleano commentedAfter applying the patch, everything works fine.
Comment #29
penyaskitoI've merge the usage of the patch in the gh repo. This looks good to me.
We need to decide yet if we are going to provide these blocks, or re-purpose this to get the patch in core.
Comment #30
plopescComment #32
plopescComment #34
plopescCreated MR based on latest @gxleano's patch, including basic test coverage.
Tests are green, so let's get it reviewed!
Comment #35
smustgrave commentedLeft a few small comments.
Also seems like will need a change record for the new block.
Comment #36
plopescThank you for your review @smustgrave
Added the missing type hints and created the Change Record draft (https://www.drupal.org/node/3414904)
Comment #37
smustgrave commentedTested this on a standard install of 11.x
Applied the MR and cleared cache via drush
Went to the performance page and everything still appears the functional and the same.
Went to block layout and placed the new "Clear cache" block into the content region.
Confirmed it's there.
Clicking it appeared to clear the cache, same as performance page.
Issue summary + CR are present and appear completed.
Test coverage appears to cover the placement and usage.
+1 RTBC from me.
Comment #38
longwaveBlock plugins should use attributes instead of annotations since 10.2.0.
Comment #39
gxleano commentedComment #40
longwaveYou can also delete the annotation, we don't need both.
Comment #41
gxleano commentedThanks for the quick review @longwave!
I though that it was removed in the MR.
Comment #42
gxleano commentedComment #43
smustgrave commentedFeedback appears to be addressed.
Comment #44
quietone commentedI'm triaging RTBC issues. I read the IS, the comments and the CR. I didn't find any unanswered questions.
This is changing the UI and should be tagged Usability as well as provide screenshots, available from the issue summary. Not sure if this qualifies for a usability review.
The CR has all the data but it should put how to find the new block at the beginning instead of the end. Even a screenshot would help. It also has a error in tense, 'displayed name' should be 'display name'.
The issue summary explains that this feature is for the Dashboard initiative. The issue discussing that proposal is still active and therefor not approved. I am not aware that we make changes for unapproved plans. What other support is there for this feature?
Comment #45
quietone commentedComment #46
plopescHi @quietone.
According to your last comment, I made the following changes:
As part of the dashboard initiative some blocks that could be useful for both the dashboard or administrator user in general were detected. In parallel, we are working in adding those blocks to core, so they would be already available when dashboard comes in, making dashboards more useful for admin users.
See #3327827: Provide a block for running cron from a dashboard
Comment #47
smustgrave commentedFeedback appears to be addressed.
I use admin_toolbar to quickly clear cache but can imagine being able to place this feature somewhere could be useful.
Comment #48
quietone commentedThank you for the updates, although I have not yet reviewed them all.
I asked about this issue in committer slack and this will need approval from the product managers, one of which is away until next week. I am adding tags, updating the remaining tasks and setting status to postponed.
Comment #49
pameeela commentedComment #50
nikhil_110 commentedTest Steps for Setting Up Drupal 11.x-dev
Suggestion
I checked the code and found that changes were made to
PerformanceController.phpandClearCacheForm.phpjust to remove the wrapper for Clear Cache block, which I think is not a correct change to make to the core, because I removed all the code forPerformanceControllerandClearCacheFormand checked that it looks like the default cache block. my thought is that you can do all this inside the plugin file itself because a new block is created for the dashboard. It would be correct to do so. I have added a screenshot of the removed code please checkComment #51
gábor hojtsyAs a Drupal product manager, I think the feature makes sense as a directly working button.
Comment #52
smustgrave commentedThanks @gabor
Believe this one is good then, all threads resolved on the MR. Test coverage appears to be there. Wasn't sure if we needed to add test to verify that cache is actually cleared but since the block is returning an existing form, ClearCacheForm, figured that's tested.
Comment #53
alexpottCommitted e65e788 and pushed to 11.x. Thanks!