Problem/Motivation
#2796173: Add experimental Field Layout module to allow entity view/form modes to switch between layouts adds an experimental module that extends and alters the EntityDisplay entity classes and forms.
It provides no additional paradigms or functionality other than enhancing the existing UI.
Proposed resolution
Once the module is approaching a stable release, merge it directly into those core classes instead of having an optional module, even one in the Standard profile.
Remaining tasks
N/A
User interface changes
N/A
API changes
Added EntityDisplayInterface::getDefaultRegion()
Added EntityViewDisplayInterface::getFieldFromBuild()
Added EntityViewDisplayInterface::setFieldOnBuild()
Data model changes
entity_view_display and enitty_form_display both get a layout_id (string) and layout_settings (array)
Comment | File | Size | Author |
---|---|---|---|
#95 | 2844302-95.patch | 159.38 KB | andypost |
#95 | interdiff.txt | 601 bytes | andypost |
#94 | interdiff.txt | 13.59 KB | andypost |
Comments
Comment #2
tim.plunkettComment #3
jibranWe need some kind of tag to track all the blocker. Maybe something like https://www.drupal.org/project/issues/search?issue_tags_op=all+of&issue_....
Comment #5
tim.plunkettFirst attempt at this. Includes the patches from the child issues:
#2851631: Expand EntityDisplayInterface to prepare for native layouts
#2851648: Layout regions should be in the order defined by the definition
#2851635: DefaultSingleLazyPluginCollection retains stale instance IDs
More sub-issues to come!
Comment #7
tim.plunkettThose fails are from #2851635: DefaultSingleLazyPluginCollection retains stale instance IDs, working through them there. Back to postponed for now.
Comment #8
tim.plunkettThose went in.
Comment #9
tim.plunkettMost "move this code from one place to another" patches would be small, thanks to the way handled git moves/copies.
However, in this case we are merging code into existing files. It can be hard to see where things ended up, so I've gone through the main files that are deleted to explain where they live now, or why it was removed completely.
Since it can't be installed or uninstalled anymore, no need for this code!
No need to swap out the entity classes or form classes, the code was merged into the original classes.
This is now handled by \Drupal\Core\Entity\Entity\EntityViewDisplay::buildMultiple()
This is now handled by \Drupal\Core\Entity\Entity\EntityFormDisplay::buildForm()
This was moved directly into \Drupal\Core\Entity\EntityDisplayBase
This was split into \Drupal\Core\Entity\Entity\EntityFormDisplay::applyLayout() and \Drupal\Core\Entity\Entity\EntityViewDisplay::applyLayout().
This was merged directly into \Drupal\field_ui\Form\EntityDisplayFormBase
This test is obsoleted by the overlap between \Drupal\Tests\field_ui\Functional\EntityDisplayTest and \Drupal\Tests\field_ui\FunctionalJavascript\EntityDisplayTest
This was merged into \Drupal\Tests\field_ui\FunctionalJavascript\EntityDisplayTest
This test was split into \Drupal\Tests\Core\Entity\Display\EntityViewDisplayTest and \Drupal\Tests\Core\Entity\Display\EntityFormDisplayTest
This tests uninstallation, which is no longer possible.
Comment #10
jibranI think it is safe to say that we need some manual testing and some reviews from framework manager and sub-system maintainers.
It would be interesting to count the number of days in core for these modules when this issue is fixed.
Blank spaces.
Why not call it TIM? :P
Blank spaces.
Comment #11
tim.plunkettYes, definitely will add all the "needs * review" tags, just wanted to get this more ready first.
Second, all of the trailing spaces are necessary because they're in the templates, and we are doing a strict comparison.
Comment #12
tim.plunkettRerolled this on top of #2834025: Mark Layout Discovery as a stable module
Comment #15
tim.plunkettNo interdiff since it's a reroll.
Comment #17
tim.plunkettFixed getExtraFields()
Comment #18
tim.plunkettAllow getFieldFromBuild() to work with references.
Comment #19
phenaproximaThis is a shallow review. I probably would have more questions if I did a deeper review, but overall it looks pretty good to me.
Can $variables be type hinted?
Doesn't adding methods to the interface constitute a BC break, however unlikely?
Can $element and $form be type hinted?
The doc comment is missing a @return.
I think this is named very strangely. This is more what I would expect the signature of setLayout() to be, not setLayoutId(). IMHO we should remove setLayoutId() entirely, if we have the latitude to do that, and leave setLayout() only, with this signature and logic.
Nit: setLayoutId() returns $this, so this can just directly return the result of setLayoutId().
Should this be returning by reference, to match getFieldFromBuild()'s return?
Can this description be changed? It's misleading and sounds like nothing will be rendered at all. Maybe just "Renders everything in the layout in a single region without any wrapping markup" or similar.
Should $layout_plugin_manager default to NULL to preserve BC? I think this is fine, personally, but I still thought I'd point it out.
Wat? Why is this here? It doesn't seem to be layout related...
This also seems kind of strange. I'm not sure how it ties into the layout system changes.
Comment #20
tim.plunkettThanks for the review!
1/3 These sorts of functions (preprocess, #process callbacks) all use the same signature, and the others don't typehint the array.
2) This is the interface for an entity, it's an allowed change.
4) Fixed
5) If PHP supported method overloading, I'd have them both named
setLayout()
.@phenaproxima @EclipseGc @dawehner @msonnabaum and I discussed this more, and decided to leave the code as-is but rename setLayoutId() to setLayoutFromId().
Also I realized that @phenaproxima and I had this exact conversation the first time setLayoutId went in! (#2796173-104: Add experimental Field Layout module to allow entity view/form modes to switch between layouts, point 7)
6) True, but I think it's better to be explicit
7) viewField() didn't return by reference before, so no this is fine
8) I'm just removing the description. None of the other core layouts have them.
9) This is an entity handler AND a form, both of which are exempt from BC
10/11) So here's the thing.
Render arrays are explicitly not BC safe. It even says
This means alter hook implementations may need to be updated.
hook_entity_view_alter() runs after the fields in the $build array have been relocated to their regions.
hook_entity_display_build_alter() runs directly BEFORE the layout code runs.
As such, I updated the only two problematic hook implementations.
Comment #21
tim.plunkettAnother option would be to move just the data model and API portion into the Entity subsystem, and move the Field UI changes to a follow-up.
Either way this is still blocked on #2834025: Mark Layout Discovery as a stable module.
Comment #22
dawehnerI'm wondering whether we can document a bit why getFieldFromBuild returns a referece
I was wondering whether it would be clearer to read when it would be something like: $components =
Then I was wondering though: Is the current implementation better O(*) wise? I would argue no, because isset() aka. a hashmap lookup by key is O(1), so the total complexity is O(N), which should be better than what it is now, see https://stackoverflow.com/questions/2473989/list-of-big-o-for-php-functions for a list of complexity time for all the various PHP functions.
Comment #23
tim.plunkett1) Not really sure how best to do that.
2) I had this same thought. But ARRAY_FILTER_USE_KEY is 5.6.0 only, and I couldn't figure out how to do it otherwise, and I figured that the explicit steps of filtering with the comments was okay.
Also holy god, Big O. That is a question for another day.
Comment #24
dawehner2) You could use
\Zend\Stdlib\ArrayUtils::filter
which we already ship with in core.Comment #25
tim.plunkett22.1
HEAD:
Current patch:
Possible?
I really don't care, but unless we magically solve #2846393: [PP-1] Investigate alternative approaches to moving fields in FieldLayoutBuilder::buildView(), we need a reliable way to locate the field within the build array.
22.2
The logic is a bit more complex there.
As a one-liner it'd be
But I find that completely inscrutable, so I chopped it up to this:
Didn't know we had ArrayUtils available!
It's in the zend-stdlib package, which seems to be brought in as a dependency of zend-feed, but not that we're using it explicitly don't we have to put it in composer.json directly?
Going to wait for that feedback before posting a new patch.
Comment #26
tim.plunkettAfter some discussion with others, went with the getter/setter.
Until #2867960: Merge Component composer.json files to account for them during build is done, a core/lib/Drupal/Core/Entity/component.json to ensure zend-stdlibs is included will not be respected.
But, the switch is good to make. Using a single array_filter with several isset()s instead of one array_filter, one array_intersect_key, and two array_diff_key calls is much clearer.
Also, for now I've removed the Field UI changes.
Comment #27
tim.plunkettOpened #2880746: [PP-1] Move Field Layout UI directly into Field UI as a follow-up and linked it from that issue.
Comment #29
tim.plunkettToo greedy with that last patch.
Comment #30
dawehner<3
Nice improvement, I like that.
Let's put some todo here to not require the library when we are on php 5.6?
Comment #31
Eric_A CreditAttribution: Eric_A commentedBut that never stopped us from declaring dependencies in the components anyway. (And copying some to core/composer.json to make everything actually work...)
But it's probably most effective to get #2769841: Prefer caret over tilde in composer.json in first, now that it is RTBC...
Comment #33
larowlanComment #36
andypostComment #37
tim.plunkettComment #38
aleevasTried to reroll this up to 8.7, but here is too many conflicts in many files. Is it this issue still actual?
Comment #39
tim.plunkettI'm not 100% sure we want to do this anymore.
Setting back to active for now for discussion, not a patch.
Comment #40
AaronMcHalePersonally I'm of two minds, on one hand this is a useful module and totally makes sense, but on the other hand not everyone needs it so keeping it separate means the Field UI stays simpler (cleaner? not sure what the best word is) for those who don't need it.
Comment #41
Gábor HojtsyReparenting to #3007167: [META] Enable layout builder for form displays, and deprecate field_layout after discussion with @tim.plunkett.
Comment #42
tim.plunkettWorking on this again. This is both the API and UI move at once. It could likely be split up better, but first I want to get the whole thing passing and see if we can make things a bit smoother for Layout Builder.
Comment #43
andypostIt looks great, quickly skimmed and found only nitpick
other issues are trying to kill includes so maybe better to move it to system.module?
Comment #44
Lennard WesterveldPatch is working but we had some issue's while updating:
1. The view display settings are not updated to the new settings zo field_layout needs to have a upgrade path to the core functionality like:
2. The dependentie on layout_discovery by default it breaks now selecting a new layout because layout.icon_builder cannot be found because it is not a default dependentie of core. Maybe we need to hide or make notice? when layout_discovery is not enabled?
3. Breaks parargaphs template or other templates where content.field_name is used (example paragraphs) because of the _layout structure is enabled on every EntityViewDisplay i would say that _layout only needs to be used when there is a layout selected other then default?
4. Also in field_ui is there still some old getThirdPartySettings that uses field_layout instead of the $display->getLayout see patch in new comment! (EDIT: i see that it it field_group contrib where this needs to change)
5. I see also a issue with entity_extra_field_info fields that uses hook_entity_view to insert there render array to the build but because it is moved to core now the order is not right i guess. _layout is already setup and later on the pseudo-fields is added to the render array. So that breaks the layout and shows the pseudo-fields below the layout parts.
6. How sure are we that this is going to move to core? (maybe better place in the meta issue?)
Kind regards,
Lennard Westerveld
Comment #45
tim.plunkett#44
1) Agreed. Tagging for update path + tests
2) Fixed
3) This is similar to #2966592: Figure out a way to render fields on top level in templates. Needs fixing here, agreed.
4) n/a, it was in field_group
5) extra fields *should* be added with weight, if it's not that should be investigated
6) It's in core already as an experimental module. This is one option. The other is to mark the module as hidden and deprecate it fully. It could then be resurrected in contrib.
Here's a reroll and a fix for #44.2
Comment #46
Lennard WesterveldHere is a patch of #45 for Drupal 8.6.10
With a additional patch for making the _layout optional only when not the default layout is selected that also can apply on 8.7.x #45 that fixes issues for templates that already created with for example `{{content.field_content}} ` not causing errors.
Comment #49
Lennard WesterveldNeeds reroll for 8.7.0 and 8.8.x
Comment #50
tim.plunkettReroll
Comment #52
tim_djReroll for 8.7.x
Comment #53
tim.plunkettThis isn't going in to 8.7 so there's no need to post rerolls for that.
Comment #54
AaronMcHaleSomething that I've noticed, and it annoys me, is that when Layout Builder and Field Layout are installed, Field Layout is completely gone on the Manage Display tab, but not on the Manage Form Display tab.
Is that a Field Layout thing, or a Layout Builder thing? Because I actually find myself wanting to use both Field Layout and Layout Builder, just on different Entity Types.
So if that's a Field Layout thing, I'd like to suggest "fixing" that here so it doesn't happen.
Comment #56
Lennard WesterveldSo where are almost 1 year further, what are the plans? about this issue?
Comment #57
SKAUGHTlots to do in the world.. status is needs work!
Comment #58
andypostComment #59
aleevasI've tried to reroll patch from #52
Comment #60
aleevasWas fixed coding standards
Comment #61
Web-BeestI've applied the patch #60, but it fails (the patch works but Drupal then craps out).
In /core/lib/Drupal/Core/Entity/EntityDisplayBase.php in getPluginCollection() the DefaultSingleLazyPlugin class is used, but not imported.
Fixed by adding
use Drupal\Core\Plugin\DefaultSingleLazyPluginCollection;
Comment #62
Web-BeestComment #63
andypostprobably layout should be applied before alter
nitpick
Comment #65
ravi.shankar CreditAttribution: ravi.shankar at OpenSense Labs commentedHere I have made changes as suggested in comment #63.
Comment #67
ridhimaabrol24 CreditAttribution: ridhimaabrol24 at Srijan | A Material+ Company for Drupal India Association commentedReroll patch for Drupal 9.1
Comment #68
Hardik_Patel_12 CreditAttribution: Hardik_Patel_12 at QED42 commentedRerolled patch 9.1.x as patch #67 failed to apply.
Comment #69
ridhimaabrol24 CreditAttribution: ridhimaabrol24 at Srijan | A Material+ Company for Drupal India Association commentedComment #70
ravi.shankar CreditAttribution: ravi.shankar at OpenSense Labs commentedBack to Need Work as patch #69 didn't pass the tests.
Comment #71
ridhimaabrol24 CreditAttribution: ridhimaabrol24 at Srijan | A Material+ Company for Drupal India Association commentedComment #72
ridhimaabrol24 CreditAttribution: ridhimaabrol24 at Srijan | A Material+ Company for Drupal India Association commentedComment #73
ridhimaabrol24 CreditAttribution: ridhimaabrol24 at Srijan | A Material+ Company for Drupal India Association commentedComment #74
Hardik_Patel_12 CreditAttribution: Hardik_Patel_12 at QED42 commentedThere are errors shown by test bot, which are as below.
Comment #75
ridhimaabrol24 CreditAttribution: ridhimaabrol24 at Srijan | A Material+ Company for Drupal India Association commentedFixed coding standards mentioned in #74
Comment #76
ridhimaabrol24 CreditAttribution: ridhimaabrol24 at Srijan | A Material+ Company for Drupal India Association commentedComment #77
Sivaji_Ganesh_Jojodae CreditAttribution: Sivaji_Ganesh_Jojodae commentedComment #78
aleevasJust re-rolled against 9.1
Let's see that test bot will say
Comment #79
aleevasNext try
Comment #80
aleevasFixed coding standards issues and fixed wrong path for these tests in patch file:
Comment #81
durgeshs CreditAttribution: durgeshs as a volunteer and at Srijan | A Material+ Company for Drupal India Association commentedComment #82
durgeshs CreditAttribution: durgeshs as a volunteer and at Srijan | A Material+ Company for Drupal India Association commented@aleevas,
#80 is applied on local.
I have removed some unused use statement, I tried to check test cases but there are failed a lot of test cases, need to work for test cases.
Comment #85
piggito CreditAttribution: piggito as a volunteer and at Skilld commentedI ported patch #82 for d8.9 for anyone else needing it.
Comment #86
ankithashettyRerolled the patch in #82 and tried to fix test failures.
Thanks!
Comment #87
ankithashettyFixing custom command failure errors in #86, thanks!
Comment #89
grathbone CreditAttribution: grathbone at Elevated Third commented#87 was not applying, and when I rerolled it actually wouldn't work because of missing getLayout() in EntityDisplayBase. Ended up doing a mixture of the last instance with getLayout(), which was from #75, and the most recent rebase, #87.
Some other issues I ran into:
Comment #90
grathbone CreditAttribution: grathbone at Elevated Third commentedAmendment to my comment above (#89): fixing namespacing issue for an old Zend reference. New patch attached.
Comment #91
andypostStill needs proper reroll
Comment #92
tim_djreroll of #90 for 9.3.x
Comment #93
andypostComment #94
andypostFixed CS and some test failures, added few todos as not sure this methods are needed
Comment #95
andypostfix more cs
Comment #100
coaston CreditAttribution: coaston commentedIs there any progress ?
Comment #101
donquixote CreditAttribution: donquixote as a volunteer commentedI think this is the same direction as this! #3389432: Make regions and fields pluggable or alterable in EntityDisplayFormBase