[2.0.0-beta1] No entity context in layout builder.

Created on 14 July 2024, 3 months ago
Updated 13 August 2024, 2 months ago

Problem/Motivation

ComponentLayout does not provide an entity context to form.

Proposed resolution

Create the context and provide it to buildConfigurationForm and buildComponentRenderable

πŸ“Œ Task
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany Christian.wiedemann

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

Merge Requests

Comments & Activities

  • Issue created by @Christian.wiedemann
  • Assigned to Christian.wiedemann
  • Status changed to Needs review 3 months ago
  • πŸ‡©πŸ‡ͺGermany Christian.wiedemann

    It's not so easy to access the entity inside layout forms. This should work now in every case.

  • πŸ‡ΊπŸ‡ΈUnited States sea2709 Texas

    I checked out your fix and did some testing. I created a SDC component "Call To Action", and I had a paragraph type "Call To Action". I used Layout Builder to configure the paragraph display with a SDC component "Call To Action" section. I selected Entity as "Paragraph", it's interesting that if I use "Token" as a source for each prop, it works, but if the source is "Data from a field", it doesn't work.

  • πŸ‡«πŸ‡·France just_like_good_vibes PARIS

    Hello sea2709, thank you for your feedback.
    About your test, is your Call to Action Body a prop or a slot?
    when you say, it doesn't work, did you mean that when you select the source "Data from a field", and then you select a specific field,
    then, no source is showing?

    if no source is showing, that could mean ui_patterns couldn't find a compatible source for the field you have selected and the prop (or slot) you are trying to set a value for.
    There may be a bug indeed, there may be a small context requirement missing. If you were trying to extract a field property from the source "data from a field", the field property can only show in certain conditions (at least your field needs to be a single value field) and the current implementation seems to have a little bug (in your case, if i am not wrong "field_granularity:item" should have been in the context_requirements context)

  • πŸ‡«πŸ‡·France just_like_good_vibes PARIS

    i just added a very small fix in the MR of Christian to cope with the case you provided. thank you :)

  • Status changed to Needs work 3 months ago
  • πŸ‡«πŸ‡·France pdureau Paris

    Hi Christian, do you need to do something else here?

  • πŸ‡ΊπŸ‡ΈUnited States sea2709 Texas

    Thanks for working on this.

    The fix worked! I was able to use layout builder to configure a paragraph display. In the section configuration, I selected a SDC component, and select "Paragraph" as an entity, and then selected the source as "Data from a field", and configured the appropriate fields and field properties. All of fields in my component are props.

  • πŸ‡«πŸ‡·France just_like_good_vibes PARIS

    good news for the fix, many thanks for the rapid feedback :)

  • πŸ‡«πŸ‡·France pdureau Paris

    Mikael, can you have a look?

  • Assigned to Christian.wiedemann
  • πŸ‡«πŸ‡·France pdureau Paris
  • Status changed to Needs review 2 months ago
  • πŸ‡©πŸ‡ͺGermany Christian.wiedemann

    I removed token context mapping in this context. Sources should not have any kind of context mapping because we have DerivableContext handling

  • πŸ‡«πŸ‡·France just_like_good_vibes PARIS

    Hello,
    in this issue, we are trying to solve three different problems :
    - no entity in layout plugin (the current issue subject)
    - a missing peace in derivable contexts (to detect cardinality one in fields and inject the correct context requirement in order for sources to show up)
    - a need to correct token source in order for it to work properly in any of our drupal plugin implementations.

    Let's split work into three different issues, that will help to merge faster.
    i will create the corresponding issues for Token and DerivableContext,
    christian i will update the codes in the three issues, ok ?

  • πŸ‡«πŸ‡·France just_like_good_vibes PARIS

    ok, i created the two new issues,
    i will report the corresponding codes to each of them and simplify the code of the current issue, ok for you Christian :) ?

    - https://www.drupal.org/project/ui_patterns/issues/3465821 πŸ› [2.0.0-beta1] Field cardinality, and derivable contexts Active
    - https://www.drupal.org/project/ui_patterns/issues/3465823 πŸ› [2.0.0-beta1] Token source and entity contexts Active

  • πŸ‡«πŸ‡·France just_like_good_vibes PARIS

    in this issue, we can also fix a typo in method calculateDependencies of ComponentLayout

    ui_patterns_layout -> ui_patterns_layouts

  • Assigned to Christian.wiedemann
  • Status changed to Needs work 2 months ago
  • πŸ‡«πŸ‡·France just_like_good_vibes PARIS

    Hello,
    now this work has be to rebased and corrected (phpstan, phpcs).
    Christian, would you like me to do it ?

  • Assigned to pdureau
  • Status changed to Needs review 2 months ago
  • πŸ‡«πŸ‡·France just_like_good_vibes PARIS

    I corrected the initial bug, but added a lot of other things :
    - changed the discovery of layout plugins (deleted the hook in .module)
    - BIG CHANGE : i introduced a new service in the main module to help cope with contexts, the service is used in the different Drupal plugins (blocks, field formatters, field layouts) to have clean and centralized way of doing context guessing. This has simplified plugins, which is a good thing (simplified service injection and simplified logic of context handling)
    - refactored tests to have a base class for doing rendering tests : lot of new stuffs, inspired and extended from the work we started in ui_patterns_field_formatters.
    - added tests for field_layout in different simple conditions: field_layout, layout_builder.. to be continued.

  • Status changed to Needs work 2 months ago
  • πŸ‡«πŸ‡·France pdureau Paris

    ComponentBlock in BlockLayout: βœ…

    ComponentBlock in Layout builder: ❌

    • any slot or prop, "Data from a field" doesn't work: i can select a field, but no a source related to this field.
    • Also, integer enum prop, I have "Data fom a field" source and I see all fields. Is it normal? I am expectign no field at all (because enum) or only fields with integer property.
    • Other context related sources (entity links..) seem to be OK)

    Field Formatter in Layout builder: ❌

    • same issue with "data from a field"
    • Other context related sources (Entity links, field property, field formatter...) seems to be OK)

    Field Formatter in Manage display: βœ…

    Layout in Layout builder: ❌

    • same issue with "data from a field"
    • Other context related sources (Entity links, field property, field formatter...) seems to be OK)
  • Status changed to Needs review 2 months ago
  • πŸ‡«πŸ‡·France just_like_good_vibes PARIS

    it was working with drupal 10.3 (my test install) and not with drupal 11 (your test install)

    after investigations, i have found we have been victims of https://www.drupal.org/project/drupal/issues/3303557 πŸ“Œ Deprecate and remove the AJAX replace method Fixed .
    corrected :) !
    please re-test with drupal11

  • πŸ‡«πŸ‡·France pdureau Paris

    Merged.

    Follow up: πŸ“Œ [2.0.0-beta2] ContextHelper cleaning Fixed

  • Issue was unassigned.
  • Status changed to Fixed 2 months ago
  • πŸ‡«πŸ‡·France pdureau Paris
  • Status changed to Fixed 2 months ago
  • πŸ‡«πŸ‡·France pdureau Paris
Production build 0.71.5 2024