Problem/Motivation
I was testing the "Enforce auto logout on admin pages" feature in #3579880: Improve documentation for Enforce auto logout on admin pages setting, and used the "Automated logout info" block:
For easier debugging, I added the "Automated logout info" block to both the regular, as well as the admin theme. Under administration ("back end") pages such as
/admin/config/peopleas well as/node/add/pageand see this messageAutomated logout info
Autologout does not apply on the current page, you will be kept logged in whilst this page remains open.
If I add the "Automated logout info" block, and then enable "Enforce auto logout on admin pages" under /admin/config/people/autologout and save the page, the text in the block remains unchanged.
I need to rebuild caches, for the block text to reflect the actual settings:
Automated logout info
You will be logged out in 1 min if this page is not refreshed before then.
Steps to reproduce
- Enable the "Automated logout info" block
- Enable "Enforce auto logout on admin pages" (
/admin/config/people/autologout), but see the same text in the block - Rebuild caches, and see the actual settings
Proposed resolution
Could rebuilding the caches be added as a last step, after saving configuration via the settings page?
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork autologout-3580475
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:
Comments
Comment #2
ressaComment #5
deaom commentedAdded an autologout settings cache to the warning block so the cache gets invalidated after the settings are saved. As it needs a test, setting status to needs works.
Comment #6
ressaWow, that was fast, thanks @deaom 🚀
I can confirm that the code works perfectly, and the text is updated immediately, after clicking "Save configuration", so that bit is solved.
Comment #7
deaom commentedTest is added so this is now ready for review.
Comment #8
ressaBeautiful work @deaom, the test will catch an uncached
AutologoutWarningBlockblock, so the test currently passes as expected, as can be seen in the MR's "testAutologoutWarningBlock" test:https://git.drupalcode.org/issue/autologout-3580475/-/pipelines/774814/t...
If I comment out the five new lines in
src/Plugin/Block/AutologoutWarningBlock.php(which adds theconfig:autologout.settingscache tag) and run the test, it fails as expected, catching the regression.Comment #9
the_g_bomb commentedAdded a couple of typo fix suggestions, but other than that I am good with this.
Comment #10
ressaComment #11
ressaThanks for catching those typos @the_g_bomb, I have applied your suggestions.
Comment #12
ericgsmith commentedFixes the issue - suggestions applied so this looks back to RTBC
Comment #13
the_g_bomb commentedMerged.
I will consider a follow-up to override the getCacheTags() method on the block class, which would cover all return paths, instead of just the final return path in build().
I am wondering if the return [] path (when preventJs() is true) will not carry the tag, meaning a settings change that affects preventJs()'s return value wouldn't invalidate that cached empty result.
Comment #14
the_g_bomb commentedComment #16
ressaVery nice, thank you all for fixing this so quickly! It's really nice to see the number of open issues steadily dropping.