How to use extra fields in component

Created on 25 February 2024, 4 months ago
Updated 4 April 2024, 2 months ago

Problem/Motivation

I created a component to display the header for a content type, containing a title, back link, add to any links, and some details.

The back link and add to any are added via hook_entity_extra_field_info, and the value set in hook_entity_view().

When I try to render the view mode as a component and insert the back link or add to any field, it throws an error:

InvalidArgumentException: Field addtoany is unknown. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField() (line 616 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).

Drupal\Core\Entity\ContentEntityBase->get('addtoany') (Line: 159)
Drupal\sdc_display\Util::Drupal\sdc_display\{closure}(, 'addtoany')
array_reduce(Array, Object, ) (Line: 160)
Drupal\sdc_display\Util::computeSlotValues(Array, Array, Array, Array, Object) (Line: 301)
sdc_display_entity_view_alter(Array, Object, Object) (Line: 545)
πŸ’¬ Support request
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @mortona2k
  • e0ipso Can Picafort

    @mortona2k did you solve this issue?

  • πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

    Including the component in the display mode template.

    {{ include('custom_theme:content-header', {
      back_link: content.back_link ?? '',
      artwork: content.field_artwork.0,
      image: content.field_image,
      details: content.field_artwork_details
    }) }}
  • e0ipso Can Picafort

    Including the component in the display mode template.

    Thanks for reporting back. I feel that we should aim to fix this issue, given that avoiding display mode templates is the main goal of this module.

Production build 0.69.0 2024