Problem/Motivation

Auto (and raw) formatters do not display bundle value for paragraphs.

Steps to reproduce

Add type to paragraph's custom elements display and select any formatter. Check api response of node where this formatter is used. type attribute is empty for anonymous user.

Proposed resolution

Create a custom formatter.

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

useernamee created an issue. See original summary.

fago’s picture

Status: Active » Needs review
fago’s picture

Status: Needs review » Needs work

see MR comments

arthur_lorenz made their first commit to this issue’s fork.

arthur_lorenz changed the visibility of the branch 3556241-entity-reference-id-formatter to hidden.

arthur_lorenz changed the visibility of the branch 3556241-entity-reference-id-formatter to active.

arthur_lorenz changed the visibility of the branch 3556241-create-a-type to hidden.

arthur_lorenz’s picture

Status: Needs work » Needs review

Reworked the MR based on @fago's review feedback:

1. Moved to main module — formatter is now in custom_elements, not custom_elements_extra_formatters.
2. More generic, but scoped — renamed to BundleTypeCeFieldFormatter (plugin ID entity_bundle_type). Instead of being
restricted to fields named "type", it's now applicable to any entity reference field whose target type is a bundle
config entity (node_type, paragraphs_type, etc.) via isApplicable() + getBundleOf().
3. No entity loading when not needed — reads target_id directly when skip_access_check is enabled.
4. Configurable access check — added skip_access_check boolean setting (default FALSE). When enabled, outputs the
bundle ID without loading the entity or checking access.

Kernel test covers: attribute output, slot output, access check enforcement, and applicability checks.

arthur_lorenz’s picture

StatusFileSize
new11.02 KB

Attached patch file

fago’s picture

Status: Needs review » Needs work

thx! this looks pretty good already. I added some rather minor remarks, but let's make sure we re-use existing helpers. see MR!

arthur_lorenz’s picture

Status: Needs work » Needs review
StatusFileSize
new10.15 KB

Thx, addressed review feedback in the latest push:

1. Use trait helpers for output: Added CustomElementsFieldFormatterUtilsTrait and replaced manual slot/attribute/flatten logic with $this->setMultipleValue().
2. Defensive isApplicable: Added early return for empty $target_type, and simplified to use $field_definition->getSetting('target_type') instead of going through getFieldStorageDefinition() (since FieldConfigBase::getSetting() already falls back to storage settings).
3. Consolidated tests: Merged 5 test methods into 3 to reduce PHPUnit setup overhead — slot/attribute checks are now combined in testOutputWithSkipAccessCheck, and applicability checks in testIsApplicable.

fago’s picture

Status: Needs review » Reviewed & tested by the community

thx, this seems all good now! let's do some more testing before we merge though!

  • fago committed 185db891 on 3.x authored by arthur_lorenz
    feat: #3556241 Add a type formatter that displays the bundle IDs of an...
fago’s picture

Status: Reviewed & tested by the community » Fixed

works well! Merged.

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.