Problem/Motivation
The footnotes_group extra field added via footnotes_entity_view() does not set cache contexts, cache keys, or entity cache metadata. This is inconsistent with FootnotesGroupBlock, which correctly sets:
- route cache context
- Cache keys derived from the entity's cache tags
- Entity-level cache metadata via CacheableMetadata
Additionally, #create_placeholder => TRUE is used without providing #cache['keys'], which Drupal's render system requires when creating placeholders. This can cause stale or incorrect footnote output when the extra field is used instead of the block (e.g. when placing footnotes_group via the node display settings rather than Layout Builder).
This is related to #3098138 which introduced the block with correct cache handling, but the extra field hook was not updated to match.
Steps to reproduce
- Enable the Footnotes module and configure a text format with the Footnotes filter.
- On a content type display, enable the Footnotes group extra field (rather than using the block).
- Create a node with footnotes in a body or text field.
- View the node, footnotes may render correctly on the first load.
- With page caching enabled, view a second node, stale footnote output from the previous node may appear.
Proposed resolution
Mirror the caching approach already used in FootnotesGroupBlock::build():
- Switch to
#create_placeholder => FALSE(consistent with the block) - Set
#cache['keys']using the entity's cache tags - Apply route cache context and entity cache metadata via
CacheableMetadata
| Comment | File | Size | Author |
|---|
Issue fork footnotes-3589834
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
layalkPatch attached.
Comment #3
scott_euser commentedThanks for the detailed explanation and patch. Can you please update to a merge request & add appropriate test coverage? Thanks!
Comment #5
layalkComment #7
scott_euser commentedThanks, I agree with the change and makes sense.
The test coverage was testing that the code is as written, but I added a functional test to it to actually show that the cache shared and therefore wrong without the code change, and is as expected after the code change.
Merged in now, thank you!