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_readonly module.
  • 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?

Comments

daniel_j created an issue. See original summary.

daniel_j’s picture

cilefen’s picture

Status: Active » Needs review
tedfordgif’s picture

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

Status: Needs review » Needs work

The last submitted patch, 2: drupal-3258433-2-split_performance_form.patch, failed testing. View results

cilefen’s picture

Status: Needs work » Needs review
vikashsoni’s picture

StatusFileSize
new7.99 KB

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

tedfordgif’s picture

@vikashsoni I'm not sure what you're doing wrong, but this works for me:

$ git clone https://git.drupalcode.org/project/drupal.git
...
$ cd drupal
$ git checkout 9.3.x
$ curl -s 'https://www.drupal.org/files/issues/2022-01-13/drupal-3258433-2-split_performance_form.patch' | patch --dry-run -p1
checking file core/modules/system/src/Controller/PerformanceController.php
checking file core/modules/system/src/Form/ClearCacheForm.php
checking file core/modules/system/src/Form/PerformanceForm.php
checking file core/modules/system/system.routing.yml
$ curl -s 'https://www.drupal.org/files/issues/2022-01-13/drupal-3258433-2-split_performance_form.patch' | patch -p1
patching file core/modules/system/src/Controller/PerformanceController.php
patching file core/modules/system/src/Form/ClearCacheForm.php
patching file core/modules/system/src/Form/PerformanceForm.php
patching file core/modules/system/system.routing.yml
$ git status
On branch 9.3.x
Your branch is up to date with 'origin/9.3.x'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   core/modules/system/src/Form/PerformanceForm.php
	modified:   core/modules/system/system.routing.yml

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	core/modules/system/src/Controller/PerformanceController.php
	core/modules/system/src/Form/ClearCacheForm.php

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs change record

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

tedfordgif’s picture

Version: 9.5.x-dev » 10.1.x-dev
Assigned: Unassigned » tedfordgif

I'll work on the CR.

tedfordgif’s picture

Assigned: tedfordgif » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs change record

Added draft change record https://www.drupal.org/node/3350667

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Will mark this but think we could change this to a feature request and add test coverage.

catch’s picture

Status: Reviewed & tested by the community » Needs review

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

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new165.56 KB
new165.22 KB

#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

before

After

after

quietone’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record updates

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

$ git grep 'submitForm.*Clear all caches' | awk -F: '{print $1}' | sort -u | nl
     1  core/modules/block/tests/src/Functional/BlockInvalidRegionTest.php
     2  core/modules/config_translation/tests/src/Functional/ConfigTranslationCacheTest.php
     3  core/modules/menu_ui/tests/src/Functional/MenuLinkReorderTest.php

Next, I read the CR. I think it needs some improvement and here is what I found:

  • "This could impact any custom or contrib modules using hook_form_alter to modify the Clear Caches button behavior, although there are no known examples at present.". And yet the steps to reproduce show the problem with a contrib module. So, that statement seems to be incorrect. Or, am I missing something?
  • "The Clear Caches button". It will be clearer if this uses the actual text of the button, 'Clear all caches'.
  • The first sentence should be split into two to make it easier to understand.
  • The version field should be completed.

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.

daniel_j’s picture

Status: Needs work » Needs review

@quietone I have updated the CR to address your concerns.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs change record updates

CR changes look good. Hopefully makes it for 10.1

  • catch committed 73c3cea7 on 10.1.x
    Issue #3258433 by daniel_j, smustgrave, tedfordgif, quietone: Clear...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed 73c3cea and pushed to 10.1.x. Thanks!

longwave’s picture

Published the change record.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.