Provide a block for clearing caches from a dashboard

Created on 2 April 2023, over 1 year ago

Problem/Motivation

We want to have a block in the admin dashboard for clearing caches.

Proposed resolution

Provide a block. See https://www.drupal.org/project/3327580/issues/3327827 โœจ Provide a block for running cron from a dashboard Needs work as an example.

Remaining tasks

Patch. Tests.

User interface changes

New block available.

API changes

None.

Data model changes

None.

โœจ Feature request
Status

Active

Version

11.0

Component
Baseย  โ†’

Last updated 1 day ago

Created by

๐Ÿ‡ช๐Ÿ‡ธSpain penyaskito Seville ๐Ÿ’ƒ, Spain ๐Ÿ‡ช๐Ÿ‡ธ, UTC+2 ๐Ÿ‡ช๐Ÿ‡บ

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @penyaskito
  • First commit to issue fork.
  • Merge request !6Resolve #3351706 "Add block" โ†’ (Closed) created by elber
  • ๐Ÿ‡ช๐Ÿ‡ธSpain penyaskito Seville ๐Ÿ’ƒ, Spain ๐Ÿ‡ช๐Ÿ‡ธ, UTC+2 ๐Ÿ‡ช๐Ÿ‡บ

    Are you a bot? Please refrain to act like that. Thanks.

  • Assigned to elber
  • ๐Ÿ‡ง๐Ÿ‡ทBrazil elber Brazil

    sorry I will try to work on it.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain penyaskito Seville ๐Ÿ’ƒ, Spain ๐Ÿ‡ช๐Ÿ‡ธ, UTC+2 ๐Ÿ‡ช๐Ÿ‡บ

    There's nothing to work on this at the moment.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain penyaskito Seville ๐Ÿ’ƒ, Spain ๐Ÿ‡ช๐Ÿ‡ธ, UTC+2 ๐Ÿ‡ช๐Ÿ‡บ

    @elber You are definitely welcome to work on this. Really sorry if I looked annoyed, edited the previous comments.

  • Assigned to gxleano
  • ๐Ÿ‡ช๐Ÿ‡ธSpain gxleano Cรกceres

    I will take this issue as it has not had any feedback for a month.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain gxleano Cรกceres

    Attached patch against core.

  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ช๐Ÿ‡ธSpain gxleano Cรกceres
  • Assigned to elber
  • ๐Ÿ‡ง๐Ÿ‡ทBrazil elber Brazil

    I will review it.

  • Issue was unassigned.
  • Status changed to RTBC over 1 year ago
  • ๐Ÿ‡ง๐Ÿ‡ทBrazil elber Brazil

    Hi I took a look on it.
    Patch is good
    Issue problem was fixed
    route is also ok
    Moving to RTBC

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ช๐Ÿ‡ธSpain plopesc Valladolid

    Hi!

    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\ClearCacheForm could be a possibility as well.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain gxleano Cรกceres

    Thanks @plopesc for the feedback!
    I will work on this new form.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain gxleano Cรกceres
  • ๐Ÿ‡ช๐Ÿ‡ธSpain penyaskito Seville ๐Ÿ’ƒ, Spain ๐Ÿ‡ช๐Ÿ‡ธ, UTC+2 ๐Ÿ‡ช๐Ÿ‡บ

    I'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.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain penyaskito Seville ๐Ÿ’ƒ, Spain ๐Ÿ‡ช๐Ÿ‡ธ, UTC+2 ๐Ÿ‡ช๐Ÿ‡บ

    Oh the patch failed to apply and somehow didn't notice.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain penyaskito Seville ๐Ÿ’ƒ, Spain ๐Ÿ‡ช๐Ÿ‡ธ, UTC+2 ๐Ÿ‡ช๐Ÿ‡บ

    Solved the patching issue with -p2: https://github.com/penyaskito/dashboard-initiative/commit/6e3d13508f80bb...

    +++ b/core/modules/system/src/Plugin/Block/ClearCacheBlock.php
    @@ -0,0 +1,63 @@
    +    return $this->formBuilder->getForm('Drupal\system\Form\ClearCacheForm');
    

    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.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain penyaskito Seville ๐Ÿ’ƒ, Spain ๐Ÿ‡ช๐Ÿ‡ธ, UTC+2 ๐Ÿ‡ช๐Ÿ‡บ

    Attached screenshot for clarity

  • ๐Ÿ‡ช๐Ÿ‡ธSpain gxleano Cรกceres

    Thanks @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.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain gxleano Cรกceres

    I have been checking the ClearCacheForm class 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.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain plopesc Valladolid

    Hi @gxleano

    We could explore a 3rd option:

    1. Remove the details wrapper from the ClearCacheForm definition, leaving there the button alone.
    2. Add the details wrapper to the PerformanceController::build() method
    3. Include the form within the wrapper created above
  • ๐Ÿ‡ช๐Ÿ‡ธSpain penyaskito Seville ๐Ÿ’ƒ, Spain ๐Ÿ‡ช๐Ÿ‡ธ, UTC+2 ๐Ÿ‡ช๐Ÿ‡บ

    @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?

  • ๐Ÿ‡ช๐Ÿ‡ธSpain gxleano Cรกceres

    I like the option that @plopesc mention in #22 โœจ Provide a block for clearing caches from a dashboard Postponed , so I will attach the patch with this solution during the day.

    Thanks to both!!

  • ๐Ÿ‡ช๐Ÿ‡ธSpain gxleano Cรกceres
  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ช๐Ÿ‡ธSpain gxleano Cรกceres
  • ๐Ÿ‡ช๐Ÿ‡ธSpain gxleano Cรกceres
  • ๐Ÿ‡ช๐Ÿ‡ธSpain gxleano Cรกceres

    After applying the patch, everything works fine.

  • Status changed to Postponed over 1 year ago
  • ๐Ÿ‡ช๐Ÿ‡ธSpain penyaskito Seville ๐Ÿ’ƒ, Spain ๐Ÿ‡ช๐Ÿ‡ธ, UTC+2 ๐Ÿ‡ช๐Ÿ‡บ

    I'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.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain plopesc Valladolid
  • ๐Ÿ‡ช๐Ÿ‡ธSpain plopesc Valladolid
  • Pipeline finished with Failed
    11 months ago
    #77476
  • Pipeline finished with Failed
    11 months ago
    Total: 1497s
    #77479
  • Pipeline finished with Success
    11 months ago
    Total: 573s
    #77526
  • Status changed to Needs review 11 months ago
  • ๐Ÿ‡ช๐Ÿ‡ธSpain plopesc Valladolid

    Created MR based on latest @gxleano's patch, including basic test coverage.

    Tests are green, so let's get it reviewed!

  • Status changed to Needs work 11 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Left a few small comments.

    Also seems like will need a change record for the new block.

  • Pipeline finished with Failed
    11 months ago
    #77869
  • Pipeline finished with Success
    11 months ago
    Total: 542s
    #77879
  • Status changed to Needs review 11 months ago
  • ๐Ÿ‡ช๐Ÿ‡ธSpain plopesc Valladolid

    Thank you for your review @smustgrave

    Added the missing type hints and created the Change Record draft ([#3414904])

  • Pipeline finished with Failed
    11 months ago
    Total: 184s
    #77893
  • Pipeline finished with Failed
    11 months ago
    Total: 194s
    #77897
  • Pipeline finished with Canceled
    11 months ago
    #77901
  • Pipeline finished with Success
    11 months ago
    Total: 477s
    #77905
  • Status changed to RTBC 11 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Tested 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.

  • Status changed to Needs work 11 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom longwave UK

    Block plugins should use attributes instead of annotations since 10.2.0.

  • Pipeline finished with Canceled
    11 months ago
    Total: 406s
    #87223
  • Status changed to Needs review 11 months ago
  • ๐Ÿ‡ช๐Ÿ‡ธSpain gxleano Cรกceres
  • Pipeline finished with Success
    11 months ago
    Total: 526s
    #87227
  • Status changed to Needs work 11 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom longwave UK

    You can also delete the annotation, we don't need both (or the duplicate class doc block).

  • ๐Ÿ‡ช๐Ÿ‡ธSpain gxleano Cรกceres

    Thanks for the quick review @longwave!

    I though that it was removed in the MR.

  • Status changed to Needs review 11 months ago
  • ๐Ÿ‡ช๐Ÿ‡ธSpain gxleano Cรกceres
  • Pipeline finished with Success
    11 months ago
    Total: 644s
    #87232
  • Status changed to RTBC 11 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Feedback appears to be addressed.

  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand quietone

    I'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?

  • Status changed to Needs work 10 months ago
  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand quietone
  • Status changed to Needs review 10 months ago
  • ๐Ÿ‡ช๐Ÿ‡ธSpain plopesc Valladolid

    Hi @quietone.

    According to your last comment, I made the following changes:

    • Merge 2 separated test methods into 1
    • Add block screenshots to the IS
    • Rephrase the CR and add block screenshot

    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 โœจ Provide a block for running cron from a dashboard Needs work

  • Pipeline finished with Failed
    10 months ago
    #103892
  • Pipeline finished with Failed
    10 months ago
    Total: 555s
    #103914
  • Pipeline finished with Success
    10 months ago
    Total: 493s
    #103932
  • Status changed to RTBC 10 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Feedback 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.

  • Status changed to Postponed 10 months ago
  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand quietone

    Thank 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.

  • Status changed to Needs review about 2 months ago
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia pameeela
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia nikhil_110

    Test Steps for Setting Up Drupal 11.x-dev

    1. Setup Drupal 11.x-dev.
    2. Apply the Merge Request (MR).
    3. Navigate to:
      • Administration > Structure > Block layout
    4. Place a Block:
      • Click the "Place block" button in the desired region.
      • Choose a block from the "Clear cache" section.
    5. Check the Home Page:
      • Verify that the "Clear cache" block is displayed correctly.

    Suggestion
    I reviewed the code changes made in PerformanceController.php and ClearCacheForm.php, specifically regarding the removal of the wrapper for the "Clear Cache" block. I believe this is not an appropriate modification to the core functionality.
    To test this, I completely removed the code from PerformanceController and ClearCacheForm, and observed that the "Clear Cache" block reverted to its default state.
    I suggest that the necessary adjustments should be implemented within the plugin file itself, as a new block is created for the dashboard. This approach would be more suitable.
    I have attached a screenshot โ†’ of the removed code for your review. Please take a look.

  • ๐Ÿ‡ญ๐Ÿ‡บHungary Gรกbor Hojtsy Hungary

    As a Drupal product manager, I think the feature makes sense as a directly working button.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Thanks @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.

Production build 0.71.5 2024