Views, layouts and callbacks¶
Views¶
Add the compound's sub-fields to a view of its host content. Each uses its native field type's filters, sorts and arguments. References provide relationships to target entities. Choose the sub-field itself for formatter output, or a stored column for escaped raw output. Nested compound leaves appear too.
For repeated compounds, choose whether to show each value or group by host. Access checks use the compound field on each host entity.
Layout Builder¶
Place the whole compound as an ordinary field block. To place individual
sub-fields, enable compound_field_layout_builder and follow the
layout tutorial.
Sub-field blocks use the compound's shared Manage display formatters. They do not read host-field display overrides. The compound's own Manage display has no internal Layout Builder layout editor.
Theming and callbacks¶
A sub-field formatter receives a compound_field_context entity containing the
compound's sub-fields. Its bundle is the compound ID and its label is the host label.
It has no stored identity, URL or JSON:API resource.
For status in compound speaker_card, the most specific field template is
field--compound-field-context--status--speaker-card.html.twig.
Less specific choices omit the sub-field or compound segment. Host templates such
as field--node--status--article.html.twig do not apply.
The render array's #object is this context entity. It exposes sibling
sub-fields, including their references, but no host entity. Treat it as read-only
in Twig. Internal writes to capped sub-fields must preserve the slot counts
recorded by the context.
An allowed_values_function receives the same context as its entity argument.
A callback that assumes it receives the host node cannot read arbitrary host
fields from it. Make such callbacks independent of the host, or obtain host
information through the sub-field item.
For field-type authors, FieldProxy::getEntity() answers which entity declares
the sub-field. FieldProxy::getHostCoordinates() instead returns the outermost
stored entity type, entity ID and field name for durable references.
Structural-change subscribers¶
Renames and removals dispatch
CompoundFieldSubFieldStructureEvent::NAME, compound_field.sub_field_structure_change,
once per applied plan while its lock is held. The read-only payload contains
the compound ID, renamed and removed sub-fields, and the corresponding flattened
columns including capped slots. Use these supplied column mappings.
Subscribers update their own Views, contrib or site configuration. The pipeline does not rewrite arbitrary consumers. It dispatches the event before rewriting the host configuration it manages.
For Token and Search API, use the typed-data guide.