Problem/Motivation
Some modules, such as config_readonly, alter any form inheriting from ConfigFormBase to prevent it from modifying active configuration. This is useful in sites whose configuration is controlled exclusively through deployment processes involving configuration imported from YAML. However, since the “Clear Caches” button is part of PerformanceForm, which is a config form, caches cannot be cleared in environments which enable such a module. The “Clear Caches” button should therefore live in its own dedicated non-config form.
Some might argue that this is a contrib-space problem; my counter-argument is that a form submission that does not touch configuration does not belong in a form inheriting from ConfigFormBase.
Steps to reproduce
- Install/enable the
config_readonlymodule. - Add this code to settings.php:
$settings['config_readonly'] = TRUE; - Navigate to /admin/config/development/performance and click the “Clear Caches” button
- Observe that a warning message is displayed, and caches are not cleared.
Proposed resolution
Split the system_performance_settings form into two forms. Add a controller to display the “Clear Caches” form above the “Performance” form.
Remaining tasks
None.
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
TBD?
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | Screenshot 2023-04-05 at 12.37.12 PM.png | 165.22 KB | smustgrave |
| #16 | Screenshot 2023-04-05 at 12.36.30 PM.png | 165.56 KB | smustgrave |
| #7 | 3258433--before--patch.png | 7.99 KB | vikashsoni |
| #2 | drupal-3258433-2-split_performance_form.patch | 3.88 KB | daniel_j |
Comments
Comment #2
daniel_j commentedComment #3
cilefen commentedComment #4
tedfordgif commentedThis form is already covered by functional tests that use it to clear cache and save config:
web/core/modules/block/tests/src/Functional/BlockInvalidRegionTest.php
web/core/modules/menu_ui/tests/src/Functional/MenuLinkReorderTest.php
web/core/modules/config_translation/tests/src/Functional/ConfigTranslationCacheTest.php
web/core/tests/Drupal/FunctionalTests/Installer/InstallerTranslationTest.php
There are contrib modules that form_alter the system_performance_settings form, but I'm not aware of any that alter the cache clear button. Purge (purge_ui) alters the cache duration options and captcha adds a warning as a new form element.
The config_readonly test that checks for the read-only warning will still pass.
Comment #6
cilefen commentedComment #7
vikashsoni commentedPatch not applying in drupal-9.3.x-dev showing error while going to apply patch
i have added in settings.php
$settings['config_readonly'] = TRUE;
Checking patch core/modules/system/src/Controller/PerformanceController.php...
error: core/modules/system/src/Controller/PerformanceController.php:
Checking patch core/modules/system/src/Form/ClearCacheForm.php...
error: core/modules/system/src/Form/ClearCacheForm.php:
Checking patch core/modules/system/src/Form/PerformanceForm.php...
Checking patch core/modules/system/system.routing.yml...
Comment #8
tedfordgif commented@vikashsoni I'm not sure what you're doing wrong, but this works for me:
Comment #11
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #need-reveiw-queue. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge require as a guide.
Applying patch #2 I see no visual regression as the cache clear button is still there and functional
Reviewing the code the changes look good.
I see appropriate typehints
Do think something like this should have a change record so tagging for that.
Comment #12
tedfordgif commentedI'll work on the CR.
Comment #13
tedfordgif commentedAdded draft change record https://www.drupal.org/node/3350667
Comment #14
smustgrave commentedWill mark this but think we could change this to a feature request and add test coverage.
Comment #15
catchI'm not sure whether this needs test coverage or not, but let's check the following:
1. Is there any existing test coverage of the page?
2. Manual testing to confirm there's no visual regression.
Comment #16
smustgrave commented#15.1 = There are still references to admin/config/development/performance in BlockInvalidRegionTest and ConfigTranslationCacheTest where the "Clear cache" button is pressed.
#15.2 Attaching screenshots but no visual regression.
Before
After
Comment #17
quietone commentedIt is pleasant to find an issue with an up to date issue summary and a short one too! I read the IS and the comments and I find that all the questions have been answered.
I tested the patch, using the steps in the issue summary. I can confirm that the patch fixes the problem. However, this is re-testing the patch on 9.3.x instead of 10.1.x.
I also found other tests that use the 'Clear all caches' button.
Next, I read the CR. I think it needs some improvement and here is what I found:
I am tagging for CR update.
I read the patch. Everything looks in order and the comments are easy to understand.
So, this just needs the updates to the CR and then it should be good to go.
Comment #18
daniel_j commented@quietone I have updated the CR to address your concerns.
Comment #19
smustgrave commentedCR changes look good. Hopefully makes it for 10.1
Comment #21
catchCommitted 73c3cea and pushed to 10.1.x. Thanks!
Comment #22
longwavePublished the change record.