Introduce a new source to get access to the current "i-th" referenced entity from a field entity reference in the context of component per item field formatter

Created on 14 January 2025, 6 months ago

Problem/Motivation

Currently, when using "component per item" field formater, we can access to the current i-th field property value and get the values for each component.

Unfortunately, we don't have such mechanism in the case of entity reference field, when one wants to traverse the current i-th entity referenced by a field.
Indeed, the source "Referenced Entities" is traversing all the entity referenced by a field.

let's create such a source, and we could name it "Field prop: referenced entity" ?

📌 Task
Status

Active

Version

2.0

Component

Code

Created by

🇫🇷France just_like_good_vibes PARIS

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

Merge Requests

Comments & Activities

  • Issue created by @just_like_good_vibes
  • Pipeline finished with Failed
    6 months ago
    Total: 586s
    #395811
  • Pipeline finished with Success
    6 months ago
    Total: 571s
    #395826
  • Pipeline finished with Success
    6 months ago
    Total: 594s
    #395841
  • Pipeline finished with Success
    6 months ago
    Total: 610s
    #396126
  • 🇺🇸United States dalemoore

    Thanks for your work on this fix (initially started on Drupal Slack here)

    I just tested https://git.drupalcode.org/project/ui_patterns/-/merge_requests/320.diff as a patch, and my fields are properly output into my component now! WOOHOO!

    For anyone in the future who may see this issue/doesn't have access to Drupal Slack, the issue was I was unable to output props/slots into a block type-based component that had a Paragraphs/Entity Reference Revisions field on it. I was attempting to create a Social Links component as a block type and each Socal Link was a child Paragraph (with social network, link, relationship, etc. as fields/props). I could use the "Referenced entities" option, but it would only output the first field item's values as the values (props) for all of the field items. This fix, so far, seems to correct that to where each field item has its own distinct values/props. I'll be making several more components setup similarly and test to make sure it continues to work for those!

  • 🇫🇷France pdureau Paris

    Mikael,

    I am happy Dale finds the new source useful :)

    I will do the proper review tomorrow, but I have a question.

    Is the combination of "Data from a field + "Field prop: entity" the same as "Reference entity" ?

  • 🇫🇷France just_like_good_vibes PARIS

    There is no "Reference entity" source ?

    if you mean "Referenced entities", no it's not the same :)

  • 🇫🇷France pdureau Paris

    2 feedbacks.

    Source label in form: Instead of the confusing "Field prop: entity", some proposals: "Field item: entity", "Referenced entity" (singular)... what else?

    Also, after selection, we don't see the selected source, but it will be fixed in its own ticket.

    Those 2 sources setup are now equivalent because "Reference entities" now behave like the new source:

            slots:
              title:
                sources:
                  -
                    source:
                      derivable_context: 'entity_reference:node:article:field_tags:taxonomy_term:tags'
                      'entity_reference:node:article:field_tags:taxonomy_term:tags':
                        value:
                          sources:
                            -
                              source:
                                derivable_context: 'field:taxonomy_term:tags:name'
                                'field:taxonomy_term:tags:name':
                                  value:
                                    sources:
                                      -
                                        source_id: 'field_property:taxonomy_term:name:value'
                                        _weight: '0'
                              source_id: entity_field
                              _weight: '0'
                    source_id: 'entity:field_property:node:field_tags:target_id'
                    _weight: '0'
              message:
                sources:
                  -
                    source:
                      derivable_context: 'entity_reference:node:article:field_tags:taxonomy_term:tags'
                      'entity_reference:node:article:field_tags:taxonomy_term:tags':
                        value:
                          sources:
                            -
                              source:
                                derivable_context: 'field:taxonomy_term:tags:name'
                                'field:taxonomy_term:tags:name':
                                  value:
                                    sources:
                                      -
                                        source_id: 'field_property:taxonomy_term:name:value'
                                        _weight: '0'
                              source_id: entity_field
                              _weight: '0'
                    source_id: entity_reference
                    _weight: '0'
  • Pipeline finished with Success
    6 months ago
    Total: 870s
    #397619
  • 🇫🇷France pdureau Paris

    Reviewed, but hold until @dalemoore validate it.

  • 🇺🇸United States dalemoore

    Hi @pdureau I'm out on personal leave today but will test first thing tomorrow! Thanks again for your and @just_like_good_vibes work on UI Patterns! It's truly something, should be in Core/Drupal CMS IMO

  • 🇫🇷France pdureau Paris

    Thanks for the kind words.

    It's truly something, should be in Core/Drupal CMS IMO

    You may be interested by Adopt UI Patterns 2 to prepare developers and users for Experience Builder Active

  • 🇺🇸United States dalemoore

    @pdureau Indeed, following—hopefully we will see it included in some way!

    I've tested the updated MR as a patch and don't see a noticeable difference, so if I'm not supposed to, I think it's good.

  • Pipeline finished with Success
    6 months ago
    Total: 726s
    #398974
  • Pipeline finished with Success
    5 months ago
    Total: 87s
    #407163
  • Pipeline finished with Success
    5 months ago
    Total: 51s
    #407347
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • Pipeline finished with Failed
    2 months ago
    Total: 1224s
    #483948
Production build 0.71.5 2024