Problem/Motivation
Modules that want to modify the section configuration form in layout builder may have a hard time, because there's no way to retrieve the layout plugin object. Contrib needs access to the plugin object so it can save configuration for it.
Proposed resolution
Add public getters for retrieving the layout and section, like we already did for the block configuration form in #3003666: Provide access to a Section or SectionComponent from within a $form_state
Remaining tasks
Per #3044117-49: Add getter for layout object in Layout Builder's ConfigureSectionForm:
- This is a feature request and should be testing 9.5.x instead of 9.3.x.
- And let's add a test on D10 as well.
- Once completed and passed, return to RTBC?
User interface changes
N/A
API changes
No
Data model changes
No
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #34 | interdiff_32-34.txt | 2.66 KB | segovia94 |
| #34 | expose-properties-config-section-form-3044117-34.patch | 6.5 KB | segovia94 |
| #32 | drupal-3044117-interdiff-30-32.txt | 1.2 KB | Webbeh |
| #32 | drupal-3044117-32.patch | 6.45 KB | Webbeh |
Issue fork drupal-3044117
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
Comment #2
bkosborneHere's two versions of the patch.
One simply adds a getter for the layout object, which I think would be enough for contrib.
To also provide access to the section object, more changes are needed, since the section object is either retrieve or created as needed. We'd need to create the object in the form builder and save it as a property, instead of re-creating it in the submit function. That way contrib could mess with it if they wanted to.
Comment #3
tim.plunkettComment #4
tim.plunkettNit: Retrieves
Needs tests, see #3003666: Provide access to a Section or SectionComponent from within a $form_state for inspiration
Comment #6
eescribanoc commentedI just added the tests in this patch.
Comment #7
eescribanoc commentedWhile checking the latest patch to add the tests it didn't apply so I had to repatch it to fit the core version 8.9
Comment #10
eescribanoc commentedI added 2 lines to the test so hopefully it does not fail.
Comment #11
eescribanoc commentedComment #12
eescribanoc commentedSorry, wrong naming in #10, re-uploading the interdiff
Comment #13
eescribanoc commentedAnd the missing patch that works (assumptions on how interdiff worked, sorry for spamming)
The interdiff is "interdiff_7-12.txt"
Comment #14
emerham commentedRan into an issue in contrib space where lb_ux and layout_builder_styles no longer played nicely together. This patch allows layout_builder_styles to get the current layout for the section forms.
Comment #15
bkosborneAs #14 said, this is blocking two contrib modules from being enabled together. LB Styles needs access to the layout object, and to do so it's overriding the section configure form object with a version that exposes the object. The LB UX module assumes the original form object is being used... and things break.
Comment #16
tim.plunkett+1 to RTBC.
Re: #15, LB Styles is overriding the form class of the
layout_builder.configure_sectionroute, and adding a new method. LB UX doesn't touch that route, that part is fine. But on another route, LB UX uses the original form class provided by Layout Builder. And since Layout Builder Styles' form_alter implementation assumes that that its version of that form class will always be used, it breaks.Comment #19
neograph734This was changed to needs work because of a failed test in the media library.
Since the test just passed against 9.1 and there are already 2 RTBC's, I am setting this back to RTBC.
Comment #20
catchThis needs a change record before it can be committed.
Comment #23
tim.plunkett@iStryker we already have a patch. Making an empty branch is not very helpful.
Comment #25
zterry95 commentedUpgrade the patch, so that it applible on 9.2.x
Comment #26
segovia94 commentedLooks like #25 lost the tests, so this is a re-roll for 9.3.x from #13.
Comment #27
segovia94 commentedNot sure if I'm able to RTBC when I've done the latest reroll, but this is working for me.
Comment #28
segovia94 commentedPer #20, I've added a change record that can be reviewed here: https://www.drupal.org/node/3243396
Comment #29
tim.plunkettOne thought. What about having
getCurrentSection()contain this logic, wrapped in a!isset($this->section)? Not that there's any chance of this being called before it's set currently, but just for consistency.These should have return types in PHP now, in addition to the @return docs
Comment #30
segovia94 commentedI've added in the recommendations from #29 (assuming I correctly understood the request).
Comment #31
tim.plunkettThat's exactly what I meant, thanks
s/id/ID
One nit: no space before the colon, only after.
Comment #32
WebbehNits from #31 applied. For review.
Comment #33
tim.plunkettThe
elsecase has a new call tosetLayoutSettings()(needed since thenew Section()call is done earlier now).This is also in the
if, and that one repeats the contents of$this->getCurrentSection().In fact, this now introduces the only references to
$this->section(outside the getter).I think this could be refactored as follows:
Sorry for the piecemeal reviews! I really think this is the last one 😅
Comment #34
segovia94 commentedRefactored with suggestion from #33.
Comment #35
tim.plunkettI think this is good to go! Thanks
Comment #38
spokjeBack to RTBC per #35 after #3255836: Test fails due to Composer 2.2 solved the unrelated test failure.
Comment #39
alexpottI think we should be setting $this->section in the constructor and then
The reason I'd do this is that $this->delta, $this->plugin and $this->isUpdate are all set in the constructor as well so setting this in constructor is consistent. I realise this is a revert from what was asked in #29. I'm concerned that the method is responsible for instantiation then these things could get out of sync.
Additionally it's inconsistent with $this->layout and the new getCurrentLayout(). this->layout is set in the constructor and retrieved from the section object.
Comment #40
tim.plunkettThose are all passed into
public function buildForm(), not the constructor.Comment #42
WebbehGiven #40, is this back to Needs Review, or is the feedback/NW in #39 still active/applicable?
Comment #43
ravi.shankar commentedI think this needs to be reviewed once after comments #39 and #40. So changing status to needs review.
Comment #44
smustgrave commentedThis appears to look good to me. Excited for such a feature!
If there is more to it please move back.
Comment #46
WebbehThe last patch says 'Build Successful', so manually returning it to RTBC?
Comment #47
smustgrave commentedSo I learned if it says build successfully it means there were so many failures it couldn’t output. I just triggered a 9.5 test to see what happens
Comment #48
smustgrave commented9.5 passed so don't see any issue
Comment #49
quietone commentedThis is a feature request and should be testing 9.5.x instead of 9.3.x. And let's add a test on D10 as well.
Comment #50
WebbehComment #51
neograph734@quietone I am not sure what you mean. I have spun up a Drupal 10 test, which passes. But that is so easy that I suppose you could have done that yourself.
So, then what did you mean?
Comment #52
jayhuskinsComment #53
alexpottCommitted and pushed 29849ead9e to 10.1.x and 05233f3d00 to 10.0.x and 0660f7a20c to 9.5.x. Thanks!