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

  1. Enable the Footnotes module and configure a text format with the Footnotes filter.
  2. On a content type display, enable the Footnotes group extra field (rather than using the block).
  3. Create a node with footnotes in a body or text field.
  4. View the node, footnotes may render correctly on the first load.
  5. 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

Issue fork footnotes-3589834

Command icon 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

layalk created an issue. See original summary.

layalk’s picture

Patch attached.

scott_euser’s picture

Status: Active » Needs work

Thanks for the detailed explanation and patch. Can you please update to a merge request & add appropriate test coverage? Thanks!

layalk’s picture

Status: Needs work » Needs review

  • scott_euser committed 20640d27 on 4.0.x authored by layalk
    fix: #3589834 footnotes_entity_view() extra field missing cache context...
scott_euser’s picture

Status: Needs review » Fixed

Thanks, 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!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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