Problem/Motivation
#2953656: No ability to control "extra fields" with Layout Builder added extra fields in blocks and works for extra fields which were enabled / visible in the view mode before layout_builder was enabled.
When adding new extra fields for example via HOOK_entity_extra_field_info OR https://www.drupal.org/project/extra_field now, even if you add these to the layout as blocks, their content is not rendered. Their title is rendered, which is quite strange.
Vice-versa if you disable layout_builder, move the extra_field from "Disabled" into a visible region and then re-enable layout_builder, the extra field is visible.
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#54 | interdiff_46-54.txt | 1.29 KB | danflanagan8 |
#54 | 3069578--54.patch | 4.64 KB | danflanagan8 |
#46 | 3069578-46.patch | 4.1 KB | ayushmishra206 |
#46 | interdiff_43-46.txt | 2.93 KB | ayushmishra206 |
#43 | interdiff_39-43.txt | 2.12 KB | danflanagan8 |
Comments
Comment #2
AnybodyOk I found it!
Layout builder (or anything in the below function tree) considers the "hidden" area from the display configuration. If we remove the extra field manually from the
area, it appears correctly!
So the hidden should not be considered at all here.
If that problem doesn't only occur for extra fields, we should rename the issue accordingly to something like "Layout builder should not consider 'hidden' configuration." but I guess this also happened to other fields, someone already ran into it...
Comment #4
Asterovim CreditAttribution: Asterovim as a volunteer commentedHello "Anybody" and thanks you.
I confirm that it works by deleting in hidden.
Comment #5
YurkinPark CreditAttribution: YurkinPark as a volunteer and at Skilld commentedTo allow your field be visible on layout builder "add component" form, you have to set "visible = true" in definition.
Found the case when it is possible to successfully configure and export display config with layout builder enabled. Follow next steps:
Second step is important, this will add field configuration in content
and will remove this field from hidden list.
Difference between regular fields and extra_filed fields is regular fields add its own configuration to display (to content area) when it is added, but extra_field fields don't have such trigger. Here is 2 possible solution:
Comment #6
andypostLooks more like cache issue, visibility was fixed in #3020572: Layout builder block for extra fields should appear in "Content Fields" category and not "Content"
Comment #7
YurkinPark CreditAttribution: YurkinPark as a volunteer and at Skilld commented@andypost issue us not related to visibility of blocks you can add, it is about render of display
Comment #8
YurkinPark CreditAttribution: YurkinPark as a volunteer and at Skilld commentedFollow this task for this issue #3069732: Problems with layout_builder and possibly this task can be closed i guess since problem is in extra_field module.
Comment #9
tim.plunkettYes, marking as a duplicate.
If someone can reproduce this without using that module (aka implementing
hook_entity_extra_field_info()
directly), please reopen with your code example.Comment #10
waspper CreditAttribution: waspper as a volunteer and at Skilld commentedBug is present even using
hook_entity_extra_field_info()
. For example, le't asume we have following extra-field:Without Layout builder, field works fine. It's displayed by default (keep note on property
'visible' => TRUE,
at first hook).Then, if I remove field from display, and I enable layout builder and I try to re-add field, it doesn't work. Field content is not rendered. We could to think it's needed to disable layout builder to append field to the "base" display and then, re-enable it again. But this is not desired behavior, because there could be sites with complex layouts. Also, keep in mind "visible" is already enabled into the definition.
Seems problem could reside into the
core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php::getComponent
method. It returns "NULL" even for some core fields (for example, the node "Links" field).Comment #11
waspper CreditAttribution: waspper as a volunteer and at Skilld commentedComment #12
waspper CreditAttribution: waspper as a volunteer and at Skilld commentedAgain: Just wanted to hear opinion: Attached patch is basically to ilustrate some issues. It would be great to know, if approach is concerning this class.
Comment #14
YurkinPark CreditAttribution: YurkinPark as a volunteer and at Skilld commentedPossibly, reroll will be needed
Comment #15
tim.plunkettComment #16
kostyashupenkoAgainst 9.1.x branch reroll is not needed
Comment #17
andypostAs patch fails
Comment #18
ravi.shankar CreditAttribution: ravi.shankar at OpenSense Labs commentedWorking on this.
Comment #19
ravi.shankar CreditAttribution: ravi.shankar at OpenSense Labs commentedComment #20
CulacovPavel CreditAttribution: CulacovPavel commentedNotice: Undefined offset: 3 in Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay->preSave() (line 166 of core\modules\layout_builder\src\Entity\LayoutBuilderEntityViewDisplay.php).
list (, , , $field_name) = explode($plugin::DERIVATIVE_SEPARATOR, $plugin->getPluginId(), 4);
Fix this to
if($plugin instanceof ExtraFieldBlock){
to me working thanks
Comment #21
andersen_ti CreditAttribution: andersen_ti as a volunteer and at Skilld commentedfix of #14 patch. wrong expression , see interdiff.
Comment #22
super_romeo CreditAttribution: super_romeo as a volunteer commentedThanks for patch #21, but issue from #20 still exists.
Comment #23
danflanagan8New to this issue here. I was working on #3144010: New pseudo-fields cannot be removed, InvalidArgumentException thrown and I think I solved this issue too. Can someone review this patch?This patch modifies a class that does not exist in 9.0.x, so this will only apply on 9.1.x.This patch does not work. See comment #27. Sorry!
Comment #24
danflanagan8Here's a patch that uses the same approach as the one in #23 but it's for 9.0.x and it should work in 8.9.x.This patch does not work. See comment #27. Sorry!
Comment #25
tim.plunkettNW for an issue summary update and for tests.
I have some other thoughts about the change and how best to document this code, but that should wait until after tests are written.
Comment #26
tim.plunkettActually, closing this one in favor of #3144010: New pseudo-fields cannot be removed, InvalidArgumentException thrown as the fixes are the same.
Comment #27
danflanagan8Turns out I was totally wrong about my patches in #23 and #24 solving this issue. It is not a duplicate of #3144010: New pseudo-fields cannot be removed, InvalidArgumentException thrown.
Please see comment from @sorlov on the other issue: https://www.drupal.org/project/drupal/issues/3144010#comment-13825300
Sorry about the confusion. Re-opening this issue. I plan to post a fail test soon.
Comment #28
danflanagan8Here's a FAIL patch that I think exposes the issue cleanly.
Comment #29
danflanagan8Here's the patch from #21 tested against the FAIL patch of #28. The test passes locally, which is good news.
There's a comment in #20 that may or may not be resolved yet.
UPDATE:
I'm seeing failed tests with this message:
I think that's the same thing brought up in #20.
Comment #30
danflanagan8I incorporated the suggestion from #20 (from @Regnoy) into this latest patch. See interdiff and comment #20.
Comment #31
tim.plunkett@danflanagan8 ah, okay that makes more sense :)
I think the base ID should be checked in both cases.
I've never seen parent:: calls to _other methods_ before. Why not call $this->setComponent?
Additionally, why not do this in
an override of ::init()?
Or if it's possible, from within setComponent directly?
Doing this on every preSave() doesn't feel right.
Can we possibly change ExtraFieldBlock to not need this special casing?
Nit: This could use in_array()
Idk where "pseudofield" comes from, let's call it an "extra field" like it is in the code base.
Comment #32
danflanagan8That's so funny, @tim.plunkett! I learned these as "pseudofields" a few years ago and I toss it around as if it's the standard word. In the docblock for hook_entity_extra_field_info() it reads:
Even core is a little bit confused on the matter! Anyway, changing the wording from "Pseudofield 2" to "Extra field 2" would be no problem.
As for your other comments on the patch, I haven't looked at the functional code in the patch too closely and I don't really understand what's going on. Other than the test part of the patch, I was mindlessly compiling previously posted patches and comments.
Maybe someone who worked on the previous patches could take a look?
Comment #33
danflanagan8I took some time to look into this and have a patch with a somewhat different approach than the other patches. I took @tim.plunkett's idea of looking into overriding the init() function.
Comment #34
tim.plunkettSeems to be a lot of duplication of the parent implementation. Is it possible to still call
parent::init()
and add in just the LB specific code?Comment #35
danflanagan8Yeah, that would be a good idea. Let's see if all the tests pass. If they do I'll post an updated patch with less duplicated code.
Comment #36
danflanagan8Two failed tests. The one that's in Layout Builder is an easy fix, but I think the failed test in Umami indicates my approach is no good. The new init() function moves the
links
extra field from hidden to content (like it does with all extra fields), causing the test on umami config to fail.I kind of liked overriding since it didn't require changes to any other functions, but I think now that the best approach will be to make changes to the
getComponent()
function, as was done in the patches prior to #33.Comment #37
danflanagan8Here's yet another attempt. This patch is a lot like the one in #30 but with the comments of #31 taken into account. This patch does not make any changes to preSave(). The changes to getComponent() and getSectionComponentForFieldName() are hopefully just a little bit clearer. I added a helper function to EntityDisplayBase in an attempt to keep things as clean as possible.
Comment #38
danflanagan8Comment #39
danflanagan8I started feeling like #37 contained some overkill. This new patch is basically the patch from #12 plus the test. I think @waspper had it right from the start.
Also, I never addressed this comment:
I think the only way to avoid special casing in
getComponent()
is to add something like'formatter' => TRUE
as default configuration for extra field blocks. That's pretty hacky though.Comment #40
danflanagan8Comment #41
tim.plunkettWe can't return a boolean here. The valid return types are an array or NULL. I think adding
['formatter' => []]
to ExtraFieldBlock is a pretty good idea (instead of TRUE)Missing space between , and [
Also please add TRUE as the 3rd param to in_array
Comment #42
danflanagan8@tim.plunkett
I'm not sure that and empty array would work because we typically see expressions like the following in hook_node_view to handle extra fields:
If 'formatter' is set to an empty array, which is falsey, the
Do something
won't happen. Is there something truthy we could pick that isn't as hacky-looking as TRUE?Comment #43
danflanagan8Let's try a new patch where we set 'formatter' in the extra field block to some essentially empty but not falsey array. I wouldn't be surprised to see some failed tests resulting from this change. We'll see.
Comment #44
tim.plunkettThis is looking really good!
Couple points of feedback.
Still missing a space after the comma here
According to
EntityDisplayBase::setComponent()
this is the correct fix, but only for settings/third_party_settings. Leave out label/typeCombine these two comments, and leave out the issue #.
Remove "try to" from this sentence
Nit: swap those " for '
Comment #45
ayushmishra206 CreditAttribution: ayushmishra206 at OpenSense Labs commentedComment #46
ayushmishra206 CreditAttribution: ayushmishra206 at OpenSense Labs commentedMade the changes requested in #44. Please review.
Comment #47
danflanagan8Looks like #46 addresses all the concerns from #44. I'll set this RTBC.
Comment #48
tim.plunkettIn general, you shouldn't RTBC an issue you wrote patches for.
In this case, I was about to RTBC anyway, so it's not a problem.
Thanks for your work on this!
Comment #49
danflanagan8Right, I guess I should recuse myself in such situations!
Comment #51
tim.plunkettDrupal\Tests\ckeditor\FunctionalJavascript\CKEditorIntegrationTest is an unrelated random failure. Resetting to RTBC.
Comment #52
larowlanShould there be a config-schema change to go with this - block default configuration normally maps 1:1 to a schema entry
nit: more than 80 chars here
Comment #53
tim.plunkettAh yes,
block.settings.field_block:*:*:*
should be duplicated exact as-is but asblock.settings.extra_field_block:*:*:*
@danflanagan8, can you do that so that I can reRTBC?
Comment #54
danflanagan8There ya go. I also shortened the comment called out in #52.
Comment #55
tim.plunkettThanks! I think that suffices.
Comment #57
catchCommitted b94f170 and pushed to 9.1.x. Thanks!
Comment #59
AnybodyHi @tim.plunkett and @catch. as modules like extra_field (see related issues) depend on this fix to work in layout_builder, I'd like to ask if you see a chance to backport these important fixes to 8.x to allow them to work as expected?
Comment #60
PCate CreditAttribution: PCate commented+1 for a backport of this to 8.x. Without this patch the Toc.js node field does not render.
The #54 patch applied cleanly and fixes the issue with 8.9.10 so I don't think a backport will need any modification to the patch.
Comment #61
yktdan CreditAttribution: yktdan commentedThis is still here in D9.2. When I add a field to a content type that has been configured in layout mode, the field does not appear in the layout. As above, if you get out of layout mode and go to manage fields, the field is there but disabled. If you move it to enabled and reenable layout mode it now appears, but you have lost all the layout customization in the process.
Comment #62
danflanagan8Hi @yktdan
I'm confident that this issue is resolved, but the issue summary is not very clear. This issue is specifically about "extra fields" that are not defined with
'visible' => TRUE
inhook_extra_field_info
. These field were previously not renderable by LB until they were moved out of the "hidden" region in Field UI.Is this the problem you are having?
It looks to me like you are dealing with something that may be unexpected and annoying but not a bug. If you have a node with Layout overrides (like it's customized beyond the default layout), then it no longer picks up new changes that are made to the default layout. Is that what you're running into?
Comment #63
yktdan CreditAttribution: yktdan commentedYes, I think that describes my issue.