Problem/Motivation

ComponentLayout does not provide an entity context to form.

Proposed resolution

Create the context and provide it to buildConfigurationForm and buildComponentRenderable

CommentFileSizeAuthor
#5 Screenshot from 2024-07-25 02-52-22.png68.16 KBsea2709
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

Christian.wiedemann created an issue. See original summary.

christian.wiedemann’s picture

Title: No entity context in layout builder. » [2.0.0-beta1] No entity context in layout builder.
Assigned: Unassigned » christian.wiedemann

christian.wiedemann’s picture

Status: Active » Needs review

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

sea2709’s picture

StatusFileSize
new68.16 KB

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.

I'm not sure if it's in the scope of this issue or it belongs to another issue!

just_like_good_vibes’s picture

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)

just_like_good_vibes’s picture

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

pdureau’s picture

Status: Needs review » Needs work

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

sea2709’s picture

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.

just_like_good_vibes’s picture

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

pdureau’s picture

Mikael, can you have a look?

pdureau’s picture

christian.wiedemann’s picture

Status: Needs work » Needs review

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

christian.wiedemann’s picture

just_like_good_vibes’s picture

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 ?

just_like_good_vibes’s picture

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
- https://www.drupal.org/project/ui_patterns/issues/3465823

just_like_good_vibes’s picture

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

ui_patterns_layout -> ui_patterns_layouts

just_like_good_vibes’s picture

Assigned: just_like_good_vibes » christian.wiedemann
Status: Needs review » Needs work

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

just_like_good_vibes’s picture

just_like_good_vibes’s picture

Assigned: just_like_good_vibes » pdureau
Status: Needs work » Needs review

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.

pdureau’s picture

Assigned: pdureau » just_like_good_vibes
Status: Needs review » Needs work

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)
just_like_good_vibes’s picture

Status: Needs work » Needs review

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.
corrected :) !
please re-test with drupal11

pdureau’s picture

Assigned: just_like_good_vibes » Unassigned
Status: Needs review » Fixed
pdureau’s picture

pdureau’s picture

Status: Fixed » Closed (fixed)
christian.wiedemann’s picture