Skip to content

Fix duplicated Content Block nested fields in element index columns#19197

Merged
brandonkelly merged 1 commit into
craftcms:5.xfrom
fabianhaef:fix/content-block-duplicate-index-attributes
Jul 2, 2026
Merged

Fix duplicated Content Block nested fields in element index columns#19197
brandonkelly merged 1 commit into
craftcms:5.xfrom
fabianhaef:fix/content-block-duplicate-index-attributes

Conversation

@fabianhaef

Copy link
Copy Markdown
Contributor

Description

When the same Content Block field is used in the field layouts of multiple entry types within one section, the entry index’s Table Columns picker (under the “View” button) lists each of the Content Block’s nested fields once per entry type. With, say, 10 entry types sharing one Content Block field, every nested field shows up 10 times, making it impossible to tell which one to pick.

Ordinary fields shared across multiple layouts are already deduplicated for table columns — that was added in #18220 (for #18209), mirroring the condition-builder work in #15781. Content Block fields were never included in that dedup, so their nested fields still multiply.

Steps to reproduce

  1. Create a Content Block field (e.g. “CTA”) with a couple of nested fields.
  2. Create several entry types that each include that Content Block field in their layout.
  3. Put them all in one channel/structure section.
  4. On that section’s entry index, click View → look at Table Columns.
  5. Each nested field is listed once per entry type.

This PR

Applies the same treatment #18220 gave multi-instance fields, to Content Block fields:

  • ElementSources::getTableAttributesForFieldLayouts() — Content Block instances are now grouped across the source’s field layouts by field UID + effective handle ($groupedContentBlocks), so each nested field is contributed once, keyed off a single representative layout element.
  • Element::contentBlockAttributeHtml() — because the deduplicated column key now references one representative layout element UID (which may belong to a different entry type’s layout than the element being rendered), a new private helper _contentBlockFieldFromLayoutElementUid() resolves the Content Block field by field UID + effective handle within the element’s own layout. This parallels the existing _getFieldFromAlternativeLayouts() used for multi-instance fields, but matches on the effective handle (that method matches the raw layout-element handle override, which is null for non-overridden Content Blocks).

Card and thumbnail rendering are intentionally untouched: those paths resolve against each element’s own layout using per-entry-type card config keys, so they never hit the cross-layout case.

Related

@fabianhaef fabianhaef force-pushed the fix/content-block-duplicate-index-attributes branch from f3578c5 to bd5c521 Compare July 1, 2026 19:08
@brandonkelly brandonkelly merged commit bdf8893 into craftcms:5.x Jul 2, 2026
@brandonkelly

Copy link
Copy Markdown
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants