Problem/Motivation
Layout Builder introduces a new paradigm shift in page building and block placement for content entities without introducing a block visibility mechanism.
Proposed resolution
Provide a mechanism for configuring each block/component of a layout region to have conditional visibility using core's visibility plugins similar to existing blocks.
Remaining tasks
Address feedback
Review
Repeat
Usability review
Finalize patch
User interface changes
- New "Configure Visibility" link on LB component links.
- New configuration forms for managing visibility within Layout Builder.
API changes
Visibility is added into the existing configuration schema and functionality is built into the event system so no API changes are needed.
Data model changes
See API changes.
| Comment | File | Size | Author |
|---|---|---|---|
| #272 | 2916876-mr-7501-11.3.2-272.patch | 62.35 KB | jay.silverman |
Issue fork drupal-2916876
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
tim.plunkettClearing out the issues pointing at the implementation instead of the plan.
Comment #3
larowlanComment #4
tim.plunkettComment #5
eclipsegc commentedHow about something along these lines?
Eclipse
Comment #6
eclipsegc commentedSorry for the trash in that patch. I'll fix it in the morning.
Eclipse
Comment #8
eclipsegc commentedDeveloped against preview versions of the patches we were dependent on. It's also dependent on #2922033: Use the Layout Builder for EntityViewDisplays, so this won't work w/o that.
Eclipse
Comment #10
kristen polIf I would like to test the patch, I'm unclear as to what other patches I need to apply other than from:
https://www.drupal.org/project/drupal/issues/2922033
Not sure what "Developed against preview versions of the patches we were dependent on" means.
Comment #11
tim.plunkettI'm not sure, but I believe it's only the last patch from that issue that is needed by this one.
@EclipseGc until that's in, when you post patches can you generate two? One suffixed with
-review.patchthat is code since the blockers, and one suffixed-do-not-test.patchthat contains everything since 8.6.x?Comment #12
eclipsegc commentedWill do. I'll reroll this shortly.
Eclipse
Comment #13
eclipsegc commentedOk, I didn't have a chance to reroll against only head, so this patch is dependent on #2922033: Use the Layout Builder for EntityViewDisplays comment 62. I will get a version of this patch for core Jan 18th.
There are a bunch of interesting bits in the interdiff. Most importantly, I rewrote how SectionComponents are rendered at all. This will likely need to be split out into a parent issue of this issue, but for the sake of explaining what's here, I converted SectionComponent render array building into an event which is dispatched. This is super powerful because it means other modules can get involved in the render array building process. It also means that layouts COULD potentially render things which are not blocks. Tim wrote the original code that way and I doubled down on it here. I don't think it's a feature we'll practically use, but we essentially get it for free moving to the event dispatcher. Furthermore, being able to run before or after the normal build process means that introducing something like "visibility" into that paradigm became a simple event subscriber instead of me modifying the monolith that did the render work for us (which is what the last patch did).
Net 0 for the SectionComponent class at the moment. The interdiff removes the condition manager that the first patch added, but adds in the event dispatcher service. Still, that's a practical service when I felt that the condition manager really wasn't.
I'll post more tomorrow. (I'm pretty certain visibility condition editing, not creating, is broken. So that's one of tomorrow's tasks.)
Eclipse
Comment #14
eclipsegc commentedAlso, if you're wanting to try out a full demo of what we're pursuing, this is accurate as of now, and all the patches should layer just fine:
So hopefully that helps with bootstrapping review.
Eclipse
Comment #15
eclipsegc commentedOk, I've rerolled this on top of #2937799: Allow greater flexibility within SectionComponent::toRenderArray() after abstracting that code out of this patch. Also, this should apply directly to core now with only that 1 patch applied. Layout defaults are a separate thing and I don't think it's affected by this code path at all.
I've not provided an interdiff because I actually wasn't certainly how best to get one given that much of the code I removed from the patch still exists in the code base. Whatever the case, the main patch should be significantly smaller now. Fixed a couple of docblocks I'd missed here and there.
Eclipse
Comment #16
eclipsegc commentedOk, fixed the missing end line I had in the last patch and made editing a configured visibility condition actually work now.
Eclipse
Comment #17
kristen polHmm... maybe I'm doing something wrong but here's what I did based on comment #14 and patch #16:
git clone --branch 8.6.x https://git.drupal.org/project/drupal.git layout_builder
cd layout_builder; curl https://www.drupal.org/files/issues/2922033-layout_defaults-62.patch | git apply; curl https://www.drupal.org/files/issues/2916876-16.patch | git apply; curl https://www.drupal.org/files/issues/2937159-layout_drag-2.patch | git apply; curl https://www.drupal.org/files/issues/2936642-context-2.patch | git apply; composer install
And then I added a block but I don't see any visibility info. I don't see it in the contextual links either. Perhaps I'm looking in the wrong place?
Comment #18
tim.plunkettNote, contextual links are currently cached *by your browser, per tab*.
After clearing caches, make sure you test it in a new tab.
Comment #19
eclipsegc commentedYeah, it's a totally annoying thing, but you'll need to follow Tim's directions. :-(
Eclipse
Comment #20
eclipsegc commentedAlso, the patches I've provided are against head and no longer dependent on the defaults issue, so apply these patches, and forgo the defaults patch for the time being (until it lands and I reroll).
curl https://www.drupal.org/files/issues/2937799-8.patch | git apply; curl https://www.drupal.org/files/issues/2916876-16.patch | git apply; curl https://www.drupal.org/files/issues/2937159-layout_drag-2.patch | git apply; curl https://www.drupal.org/files/issues/2936642-context-2.patch | git applyComment #21
kristen polThanks for the tips. I see the "Control visibility" in the contextual links now. It works as expected. Here's what I did:
I looked at the code as best I could for structure and formatting. Someone else should review for logic. Feedback is out of order in some cases as I went into dreditor a couple times.
Nitpick: Should be $pluginId instead of $plugin_id? (I noticed that was the convention in other places.)
Nitpick: Use single quotes?
Nitpick: Use single quotes?
Nitpick: url => URL?
Nitpick: Don't use "we're"... perhaps:
Whether the component is in preview mode or not.
which is used in SectionComponentBuildRenderArrayEvent.php
Nitpick: Same as comment above.
Nitpick: Should comment say "The condition manager."?
Question: Field delta? Isn't this the block delta?
Nitpick: Constructor above is "Creates a SectionComponentVisibility object." so it would be good to standardize on either that format or this one.
Nitpick: Use single quotes?
Nitpick: The plugin form factory.
Question: Same as above for BlockVisibilityForm.
Nitpick: The condition plugin being configured?
Nitpick: Same as above regarding constructors.
Question: Same as above for ConfigureVisibility.
"uuid" => "plugin id"
Nitpick: Same as other constructors above.
Comment #22
kristen polIn addition to #21, I went in to try to delete the condition and wasn't able to get the dropdown to show up consistently. And, the contrast is really bad which I imagine you already know.
Comment #23
eclipsegc commentedYeah, that's a failing of the css reset on the settings tray. An on-going problem in core. :-( I've reached out to people who would know how best to solve it.
Eclipse
Comment #24
tim.plunkettComment #26
neclimdulMy goodness that was a mess of a reroll. A lot has happened since this was being developed and my reroll script couldn't even find a place to cleanly apply this.
Here is a "clean" reroll and I'll take a look at the feedback.
Comment #27
neclimdulre #21
1-3. Fixed.
4. I think Url() actually. It refers to the Url class.
5 & 6. n/a. was added in another patch.
7. fixed
8. Its actually the section delta. I've updated the comments to reflect this.
9. Fixed to "Constructs a X object" based on DrupalKernel::__construct()
10. fixed
11. fixed
12. same as 8
13. fixed
14. same as 9
15. same as 8
16. fixed
17. same as 9
Re #22
I'll have to look into that more. Not styles I'm familiar with.
Comment #29
neclimdulHaving trouble running this test locally but this fixes the error with explicit tests. Still working out some of the testing but since I can't run it locally see what testbot thinks of the changes.
Comment #30
neclimdulbah, i guess i was to fast clicking through the uploads. Patch.
Comment #32
neclimdul*sigh*
Comment #34
neclimdulI have no idea where to start with the final error. Clearly the patch only adds the class once and phpunit runs the unit test suite fine locally... Testbot seems to be handling things in an unexpected way.
Comment #35
tim.plunkettWhen running locally, I get a yellow
I. With-v, I getWhich lead me here.
Comment #36
neclimdulYeah that definitely needs work I just put it there so I'd come back while testbot decided if this still integrated ok with everything since those wouldn't run locally.
Thanks for the pointer on the namespace in slack, hopefully that fixes what ever weirdness testbot experienced.
Comment #37
neclimdultest the bejesus out of the visibility propagation.
No pending "incomplete tests" or anything, this is actually... pretty good I think.
Comment #38
neclimdulTrivial conflict with #2957425: Allow the inline creation of non-reusable Custom Blocks in the layout builder. No interdiff because its not code related, just service definition.
Comment #39
johnwebdev commentedI have not looked at the code yet; but doing manual test.
The base UI still need some work:
Here are some additional opinions on the UI and UX:
When I'm updating a condition, I would like to stay on the Configure visibility, if for instance I would like to do more changes. Same goes with adding a new condition and deleting condition.
The Add a new condition should be moved down to be aligned with the button. Currently added conditions are in the middle of these.
I really, really like this feature though. It can add some additional serious power for the site builders, for instance if Layout Builder could define conditions like "Hide this field block X if field block Y is not empty", etc.
Comment #40
tedbowGreat work so far. A few questions and nits.
I don't think this contextual link will show up for existing user with existing browser session.
Maybe related to #2773591: New contextual links are not available after a module is installed
Might have to do
hook_update_Nto do something like we did insettings_tray_install()Would we need an update test for this?
Is there reason for this to be it's own event subscriber class rather than handle this in
\Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray::onBuildRender()with something like
And then move all the logic from
\Drupal\layout_builder\EventSubscriber\SectionComponentVisibility::onBuildRender()into the new\Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray::allowedVisibility()which would return an AccessResultInterface.You won't need to worry about stopping propagation either.
Missing return description
Extra blank line
Missing return description
Comment #41
tim.plunkettThis is important. And will likely make it in to 8.7 anyway. But it's not a stable blocker.
Comment #42
neclimdul1. I'm not sure I understand this completely. Probably because I only skimmed the other issue. We'd be writing an update hook to work around a bug in core? If so I'd say we just skip it since layout builder is unstable and focus on fixing the other bug. Good to know though.
2. Long story. I tried and actually had a patch rolled . I was hesitant because of the large weight gap implied a reason but skipping the forced render in BlockComponentRender seemed worth the loss of flexibility for contrib.
I realized I forgot to get the test sorted out and started looking and I came to the second reason. Or really back around to the first. BlockComponentRender makes a big assumption its working on a block and drops out immediately if it isn't. I started to force the block plugin into the section for the test to get to the right code but this triggered a realization, the gap in the weights is actually there for a reason and an important one if I understand things correctly. Sections can contain different "things" and the render event is in charge of getting it to a render array. SectionComponentVisibility is more generalized and separated to support this so it can do its logic without running into any render listeners.
So... I guess it needs to stay the way it is.
3. fixed
4. fixed
5. fixed
Its at the very least expected functionality by anyone coming from any layout system in any other version of Drupal including just using blocks in 8.x core so I'm going to mark this major. I think we could say layouts is stable but its not really for site builders until this is in but its really moot if it gets in so lets have that drag out fight in 3 or 4 months. :)
Comment #43
millionleaves commentedTrying this out on a local install of 8.6.1. A couple of UI/UX comments...
Further, I'd like to see this facility for multiple conditions in core so it's available for regular blocks as well.
Comment #44
neclimdulI'm glad the reviews seem to be mostly cosmetic and things "work". I think we can move this back to needs work as we all agree it needs some UI love.
I might be able to work on the flow.
Unfortunately, I'm going to need help with the look and feel though. My time is limited and this patch sadly has 0 CSS and the mangling is all happening as part of the default off-canvas form styling which is outside my skill set.
Comment #46
tim.plunkettComment #47
tim.plunkettComment #48
fox_01 commentedWith #2916876-42: Add visibility control conditions to blocks within Layout Builder applied to 8.7-rc1 the "control visibility" context action will not show up at every block. I have a 25/50/25 layout and in each area a block placed. First i only saw the action at the last block. After moving the blocks around and saving the layout i saw the action now at 2 of 3 blocks. Then i had to move the 3. block into the last area and it showed up there too.
Comment #49
bnjmnmWorking on the off-canvas CSS issues identified above + anything else I might run into. Patch on the way.
Comment #50
bnjmnmThis would deviate from the pattern used by several other layout builder forms that present a second off-canvas dialog to configure the choice made in the first. Keeping things in a single dialog is certainly more challenging than having a followup dialog -- I'd like to see if this was avoid for reasons in addition to implementation overhead.
The way contextual links are cached may make this tricky to implement. Would be curious if there are other ideas regarding how to visually indicate the presence of visibility rules.
Comment #51
tim.plunkettI know this issue is still being iterated on, but here's a code review all the same
Should be
_layout_builder_access: 'view'nowPlease document the magic number (aka indicate which other subscriber you are trying to run before/after)
This can be a one-liner, adding
?: [];after the get() callFeels wrong to reuse the $condition name for both. Maybe the first one from the loop should be $configuration?
This should have an issue opened (unless it's intended to be solved in this issue?)
I don't understand this line, probably deserves a comment?
Hmmmm I'll have to think about this one
This reminds me of the helpers like
\Drupal\layout_builder\Form\ConfigureBlockFormBase::getCurrentComponent()once again with
?: []Not clear at first how $visibility_conditions and $conditions differ. Probably deserves a comment?
?
This looks a little hardcoded
Wow. That is something. This definitely deserves some inline comments
Case: "Configure condition"
Why are these the same?
Here (and probably elsewhere) these should have a one-liner explaining why they are internal. Can copy/paste from other existing classes
Usually suffixed with Form
Nit, extra blank line
This is overkill, IMO
When writing prophecy mocks, use either predictions (will) or spies (should). In this case, I'd remove the willReturn as we don't care about that value
Idk that we're allowed to change this now
Comment #52
bnjmnm#51.1
Done.
#51.2
Done.
#51.3
Done.
#51.4
Agreed - did some renaming.
#51.5
Decided to address it here as it seemed important and this will likley get it to users much faster than a followup issue. The current implementaion allows a single and/or operator, as opposed to something like Views where operators can be grouped in and/or groups. If Views-style operator grouping seems necessary, that may be best suited in a followup. To help mitigate user confusion, the current behavior of the operator field is dependent on how many visibility conditions are present. When adding the first condition, the operator field is not visible since its value does not matter on a single condition.
When adding a second condition, the operator field appears above the submit button.

Once 2+ contidions are present, the operator field appears above the conditions, and there is a dedicated submit for updating the operator so it can be changed without having to go to the configuration form for one of the existing conditions

I expanded the FunctionalJavascript tests to confirm switching the operator works.
#51.6
While stepping through the code to determine this line's purpose, I saw that the same call happens in an earlier subscriber BlockComponentRenderArray, so there shouldn't be a need for it.
#51.7
Left this unchanged - no preferable alternatives immediately came to mind but it certainly inspired a hmmmm on my end as well.
#51.8
I added a trait for this
#51.9
Done
#51.10
Added comments and changed the variable names to be more self-explanatory.
#51.11 removed this, suspect it was just an artifact of an earlier iteration.
#51.12
. Refactored into multiple render elements.
#51.13
Added some comments but not entirely sure what everything there is doing @timplunkett will be following up on this. I did try refactoring to make this match the pattern of other two-dialog configs, but those (AFAIK) all use links to access the second dialog, and do not depend on any form field values from step 1.
#51.14 Changed cases here and on a few other buttons.
#51.15
It was an accurate description for both (one deals with configuring a specific rule, and the other configuring a group of rules), but I reworded to make it a little more form-specific.
#51.16 @internal is explained
#51.17 refactored class to suffix with form.
#51.18 removed blank line
#51.19
, agreed, this is indirectly covered in several other tests so I removed it.
#51.20
Did as recommended (and had to make a few other unit test changes to reflect other changes in this patch)
#51.21
Its not a critical CSS change so I removed it. There are a few other minor css changes that would be nice to add - is this something that could be added in a followup?
Also updated the forms to include the layout highlight ID so blocks are outlined when visibility conditions are being configured.
Comment #53
rlmumfordI've changed approach slightly in this patch. As noted in https://www.drupal.org/project/drupal/issues/3056907, using an EventSubscriber is too late to avoid throwing
MissingValueContextExceptions and it seems like conditions should be able to prevent that (if user X doesn't have the "staff" role then don't should the staff profile, if entity x doesn't exist then don't render it etc)This change moves the condition evaluation directly into
Section::toRenderArray()so that the component is never touched unless conditions pass.I also changed the urls to include the
{region}to match all the other routes (I also couldn't get the contextual links to appear unless I did this?)Comment #55
eclipsegc commentedNeither issue cited above gives insight into how you've managed to achieve this particular bug. Also, I question your premise. Let me explain why:
With that flow in mind, the block plugin, with its context(s) (set properly or otherwise) exists before the render array is attempted to be generated. This fact means there are two potential solutions to the problem you outline above (though again, how you got there is beyond me since the UI strictly prevents the system from getting into this sort of state in the first place).
If I've misinterpreted your issue, please elaborate further. I do not favor moving away from the EventSubscriber approach. It buys us too much.
Eclipse
Comment #56
rlmumfordHi Eclipse and thanks for your input, hopefully I can answer both your questions.
Where the Exception Gets Thrown
So the order of calls listed is correct.
The
MissingValueContextExecptiongets thrown in point 3.SectionComponent::toRenderArray()creates a newSectionComponentBuildRenderArrayEvent.SectionComponentBuildRenderArrayEvent::__construct()calls$component->getPlugin(), which callsContextHandler::applyContextMapping()which throwsMissingValueContextException. All before the event gets dispatched.How the situation arises
I'm not sure whether this is possible to do in core, but it might be if you have a block that requires the node route context and then place it on a layout that doesn't have a node route context when its displayed. In my case, I'm using the patch in https://www.drupal.org/project/drupal/issues/3001188 to add extra contexts to entity view displays, for example a particular profile related to a user account. If the profile doesn't exist for that particular user then the error gets thrown.
Comment #57
eclipsegc commentedOk great, so this is not a bug that you've managed to make happen w/o a core patch. That's good news.
Plugins don't require contexts FROM a specific place. They require contexts of a specific type (say, "node" for example). The config saves the expected key from the contexts array that was configured through the UI, so contexts that are available through the admin that cannot be calculated during the runtime of a page are unsafe. There's a fair amount of code elsewhere in core reenforcing that approach. The best thing to do for the patch in question would be to toss a try/catch around the instantiation of the plugin. If we catch, we can return something else and add higher priority event subscriber that logs the error, stops propagation and returns an empty array as the render of the block without invoking the rest of the event subscribers.
I've not looked at the patch in question, however one of the reasons we've not yet gone after "relationship" style contexts is precisely because we have to compensate for this situation in which the context is calculate-able in the administration, but doesn't actually exist during run time. I'd say it's the domain of that patch to fix. But the problem doesn't invalidate the current code path's approach. We know and understand that this is a real thing. We planned for it and have dealt with it similarly elsewhere.
@see:
\Drupal\block\BlockAccessControlHandler::checkAccess lines 92 & 122
It's not a perfect match in that case because we specifically delay context mapping until access checking in the block module approach so we can just return AccessResults in that case. In this case, our new higher priority event subscriber would need to return an empty build array, but it also needs to addCacheableDependency() for an AccessResult::forbidden() on the event itself. It all seems super achievable, but again I'd say it's outside the scope of this issue. However once this issue lands, #3001188: Make it possible to add relationships to layout builder would need to do something similar for visibility plugins to try/catch their context mapping. Still it's 3001188's issue, not this one's.
Eclipse
Comment #58
bnjmnmI agree with @eclipsegc that the changes in #53 address something that should be addressed in #3001188: Make it possible to add relationships to layout builder, so I added a patch that does this.
This patch is built off #52 and made a change to the test to account for the test module
layout_builder_test_css_transitionsbeing removed since the transition-disabling functionality is now default in core.Comment #59
jweirather commented#58 is working for me so far, RTBC +1, and THANK YOU ALL.
Will continue testing and building out some more content types with it, but so far so good.
Edit: I wanted to note that the UI looks like it could use some polish, but is fully functional and straightforward to use.
Comment #60
jdearie commentedI've installed the patch from #58 and can see the configure visibility option on my block - but when I attempt to add a condition, after htting the Add condition button, I just get the indicator of something happening, but then nothing does.
It doesn't seem to matter which condition I choose.
I'm using layout builder to configure the /user page.
I tried this on another content type that uses layout builder and had the same result.

I am on core 8.7.8 - do I need to be on 8.8?
Comment #61
chris burge commentedThanks to everyone who has committed time to this issue!
@jdearie - Yes, you'll want to test on 8.8.
I have tested patch #58 and identified the following issues:
Undefined index in BlockVisibilityForm
The following code in BlockVisibilityForm::successfulAjaxSubmit() results in undefined index notices in certain circumstances:
Notice: Undefined index: #submit in Drupal\layout_builder\Form\BlockVisibilityForm->successfulAjaxSubmit() (line 267 of /app/web/core/modules/layout_builder/src/Form/BlockVisibilityForm.php)Proposed change:
Add 'Back' button on nested form.
It would be useful to add a 'Back' button on ConfigureVisibilityForm to return to BlockVisibilityForm.
CSS hover behavior
When hovering over 'Configured Conditions' on BlockVisibilityForm, the off-canvas reset CSS needs overridden:
This is caused by '/core/themes/stable/css/core/dialog/off-canvas.base.css':
It looks like the place to override is '/core/modules/layout_builder/css/layout-builder.css'.
Page reload on some actions
In some instances, actions result in a page reload instead of a dialog-based action:
BlockVisibilityForm
Update Operator - dialog closes
Add condition - ConfigureVisibilityForm opens in dialog
Edit link - ConfigureVisibilityForm opens in dialog
Delete link - DeleteVisibilityForm opens in dialog
Close button - dialog closes
DeleteVisibilityForm
Confirm - page reload (expected that dialog closes)
Cancel - PHP Error (see below - expected that dialog closes)
Close button - dialog closes
ConfigureVisibilityForm
Add condition - page reload (expected that dialog closes)
Update - dialog closes
DeleteVisibilityForm 'Cancel' results in PHP error
When clicking the 'Cancel' button on DeleteVisibilityForm, the following error is triggered:
TypeError: Argument 3 passed to Drupal\\layout_builder\\Form\\BlockVisibilityForm::buildForm() must implement interface Drupal\\layout_builder\\SectionStorageInterface or be null, string given in /app/web/core/modules/layout_builder/src/Form/BlockVisibilityForm.php on line 117'Node Bundle' visibility condition
When would the 'Node Bundle' visibility condition be used? The block instance is already tied to a node via Layout Builder.
'Update Operator' case on BlockVisibilityForm
On BlockVisibilityForm, 'Update Operator' uses title case instead of the sentence case used elsewhere throughout the UI. Propose changing to sentence case: 'Update operator'.
Comment #63
geek-merlinGooglefood.
Comment #64
chucksimply commentedAll seems to be working well from my tests. Question though (not to hijack this thread)... is there an ability to get the current users ID so one can control block visibility on conditions that match up with the current user.
For example on the request_path condition... would be nice to type in /user/[current-user:uid] so blocks will only show on the logged-in user's account pages (or would show for everyone but the logged-in user when clicking NEGATE).
Thanks again for the work on this.
P.S. - If the above isn't an immediate possibility, maybe this is a request for token support instead?
Comment #65
tim.plunkettThis is about providing a UI within Layout Builder for the existing Conditions.
This makes no changes to the existing conditions or their functionality.
That said, I think the functionality described in #64 would make for a great standalone feature request!
Comment #66
eclipsegc commentedContext tokens are 100% a thing we should be eventually chasing down, but not a thing we really do today. They're especially useful for content blocks, but it's definitely a separate feature.
Eclipse
Comment #67
webdrips commented#58 is working for me too: RTBC +1
Comment #68
chris burge commentedNothing from #61 has been addressed. This will also need a change record before RTBC.
Comment #69
jhedstromThis addresses parts of #61:
I was going to add a test for the fatal error (clicking the cancel link) but the existing test wasn't passing locally. That test should be added still though.
Comment #70
larowlanFixes the test fails in #69
Comment #71
larowlanIn case you need a version of this on top of #3045171: Form blocks rendered inside layout builder break save there's this, there was a conflict in services.yml file
Comment #72
sam152 commentedI haven't done a detailed line by line review but I wanted to check out the patch, this is really impressive work, nice one folks!
Just a few observations made while taking it for a spin:
Testing this was kind of confusing, because all your contextual links get cached in the browser. New blocks got the links and old ones don't.
Looks like this might be worked on in #2773591: New contextual links are not available after a module is installed though.
The condition manager already implements
FilteredPluginManagerInterface, does it make sense to usegetFilteredDefinitionshere instead, so contribs like layout_builder_restrictions can choose to provide users a way of restricting this list.Also as a dev, if I decided I didn't want admins adding visibility conditions, could I use the same hook to NULL the list out and expect to see the contextual link disappear? This is perhaps a bit too much for a single issue, but perhaps worth a follow-up.
Is "Control" the right label? Seems to use a mixture of "Control" and "Configure":
Comment #73
chris burge commentedUpdated patch attached. It addresses the following:
getDefinitionsForContexts()replaced bygetFilteredDefinitions()It doesn't address:
Comment #75
neclimdulSeems to be broken by service change in #3045171: Form blocks rendered inside layout builder break save. Rerolled against 9.1.x though the same patch seems to apply to 8.9.x just fine.
Comment #77
chris burge commented@neclimdul - Can you post an interdiff from #73?
Comment #78
mrinalini9 commentedPlease find the interdiff file for #75 here.
Comment #79
mrinalini9 commentedComment #80
mrinalini9 commentedFixing test case failure issues in #75, please review.
Comment #82
mrinalini9 commentedComment #83
mrinalini9 commentedPlease ignore patch #80, I have fixed test case failure issue for patch #75 here, please review.
Comment #85
neclimdulYeah, generally you don't provide a interdiff when there's no change and you're just resolving a chunk collision like that. Such an interdiff is hard to generate and generally not helpful and confusing so you tell people you're just rerolling.
That does not seem to be equivalent.
fieldExistsclaims to need an id|name|value and is failing despite the page containing a div with the class.This passes and matches the deprecation suggestion for
assertElementPresentComment #86
neclimdulsorry, didn't mean to change the status... don't know how that happened.
Comment #87
johnwebdev commentedNo need to use a Id as selector. Use a class instead.
For blocks we use "Remove block" - do we want to be consistent with the verb here?
Should we prefix here with "layout_builder", similar to the other defined subscriber in this module?
s/component/section component
Comment #88
johnwebdev commentedShould this route be called "add_visibility" if it used for editing a existing one?
We're mixing block and section component. Should we be consistent and use one of them?
Should this be a heading element instead of bold?
When is this ever displayed?
Comment #89
naresh_bavaskarWorking on it
Comment #90
chris burge commentedIt looks like #72.3 still need addressed - "configure" vs. "control".
Comment #91
naresh_bavaskarComment #92
chris burge commentedUpdated patch attached.
The following changes have been made:
#85 - Assert is fixed.
#87.1 - Class used instead of ID
#87.3 - Service name is now prefixed with 'layout_builder.'
#88.4 - Based on the logic, that message will never appear. It's been removed.
The following changes have not been made:
#87.2 - Language remains unchanged pending additional community feedback. The use of "delete" is used for more than just the route name, it's used for the path, for the class name
\Drupal\layout_builder\Form\DeleteVisibilityForm, for a form ID, for messages, etc.#87.4 - I don't understand the proposed change.
#88.1 - I don't see a problem with the route name. We're adding a visibility condition regardless if there's an existing one or not.
#88.2 - My understanding is that blocks become Layout Builder components when they're placed in a layout. As such, I agree; however, I'll let others weigh in at this point. We would need to rename the
\Drupal\layout_builder\Form\BlockVisibilityFormclass toComponentVisibilityForm.#88.3 - I don't think a heading element would be semantically correct here. We're working with a table, so, if anything, I'd think that the condition type and its description should be separate columns with a header row. WAVE is upset that there are no
<hr>cells. I'm leaving this one open for more discussion.Comment #93
finex commentedHi, could the visibility be also set on the whole layout section other than on the single block?
Example usecase: I've created a page with a custom layout but for some days I want to hide a section. I dont't want to delete the section because in a couple of days it will be re-added.
Should I open a separate issue with this feature request or could be considered/merged on this thread?
Thank you :-)
Comment #94
boyan.borisov commented@FiNeX, you can add the same visibility rule to each of the blocks in a section. If neither from the blocks in that section are rendered the whole section won't rendered be as well.
Generally speaking having visibility rules per section will be handy for sure.
Comment #95
grayle commentedTried patch from #92, and preliminary tests worked great.
Test Case:
Layout Override (homepage):
- add a custom block (a custom copyright block in this case)
- add language visibility, only show for English
- works great
Layout Override (homepage):
- add a reusable content block
- add language visibility, only show for English
- works great
Layout Override (homepage):
- add another instance of the above reusable content block in another section
- add language visibility, only show for Dutch
- still works great
So those use cases seem to work at least.
Comment #96
grayle commentedwoops
Comment #97
eclipsegc commented@FiNeX
We'd need the layout section to support such a thing. Definitely a separate issue from this one. It needs its own acceptance criteria and evaluation of whether or not we want to actually do it.
Comment #98
finex commentedok, thanks for the feedback @eclipsegc
Comment #100
pcate commentedPatch has failing test on 9.2.
Comment #101
tim.plunkettThis is just a code review, I have not clicked through it yet.
This doesn't make sense to me. Why would we stop propagation if it's running *after* the one that does the rendering?
Also it's redundant to say that this one is 255, that's in the code on the next line. Say instead what the value is in the other subscriber (if needed).
Finally, @see cannot be parsed in inline comments. Just make it a sentence (See \Drupal...)
And actually even more finally, that fully-qualified class name is missing the class name.
This $conditions check is doing some heavy lifting. It's both guarding against the inPreview check, as well as the emptiness of $visibility.
Instead, swap the inPreview check to be a true guard condition.
if ($event->inPreview()) { return; }This isn't something we should be doing.
If you use
#type => tableyou should be able to pass #attributes instead of hardcoding this.Even with the above comment, I don't understand the choices of 3 and 30 here.
I don't think these are needed?
nit: use
ConfigureVisibilityForm::classWhy the difference?
nit: ID, URL
Looks familiar :) Any other usages of these that could be refactored to some shared code?
I think this also lives in ConfigureBlockFormBase. Worth a refactor (or follow-up?)
Is it important that it only be called once? If not, don't test that. This applies to all the other usage of it too.
When in doubt, don't use shouldBeCalled and willReturn on the same method
I didn't read all the rest coverage, but can you please remove these extraneous return/indents? It just makes it that much harder to read
Comment #102
johnwebdev commentedAdresses #101 partially, hoping to get this going again!
1. That docblock is misleading (wrong), SectionComponentVisibility runs before BlockComponentRenderArray and that's why we stop propagation. I updated the comment.
2. Added true guard condition.
3. Not sure what we should do instead.
5. I changed 3 to 0. I added the weights in an attempt to see if it's more clear, not sure.
6. Removed.
7. Fixed.
9. Fixed.
Didn't have time to address everything now unfortunately...
Leaving at NW intentionally.
Comment #103
johnwebdev commentedAdresses #101
4. That suggested change breaks the design. Leaving as is, given that we still need some design work to be done here.
8. Fixed.
10. Follow up?
11. I think follow up is fine.
12. Don't think so. Changed. Fixed double use of shouldBeCalled/willReturn.
13. Fixed.
Comment #104
johnwebdev commentedNote to self: Remember to Run code check :)
Comment #105
nedjoThe comment may refer to use of the
btag, generally discouraged in HTML5 (see for example the article "Using<b>and<i>elements").strong?Comment #106
tim.plunkettI mean both the
bas well as thehtml_tag.I would replace that whole section with
'label' => $this->t('<strong>@condition_name:</strong> @condition_summary', ['@condition_name' => $condition->getPluginId(), '@condition_summary' => $condition->summary()]),And even consider replacing
$condition->getPluginId()with$condition->getPluginDefinition()['label']or similar.Comment #107
matt_paz commentedI've been testing this a bit and it is looking good so far.
Other "User interface changes" that might be interesting to consider could include giving the user (in the preview) a hint that visibility conditions have been applied. I'm not quite sure what that would look like, but thought it might be worth passing along.
Comment #108
johnwebdev commentedAdresses #106 and fixes cspell...
Comment #110
tim.plunkettLast nit, which is also the failing test:
protected static
That said, this is still tagged
needs designCan someone record a quick walkthrough of the proposed UI, so it can be validated?
Comment #111
abhisekmazumdarI have made the suggested changes. Which can help to turn the patch green to go. I will try to create a walkthrough for the proposed UI changes.
Comment #113
tcrawford commentedWe applied the patch (#92) to a D8 for a project and it worked extremely well. We could use it with no functional changes. We had some UI issues, but I think most of these related to layout builder UI customization we have. Thank you to everyone who has contributed.
Comment #114
tim.plunkettThe issue fork is empty, @tcrawford were you planning on pushing anything up?
Comment #115
tcrawford commented@tim.plunket Thank you for your feedback. I apologize .The issue fork was created unintentionally. I only meant to leave a comment to provide our (positive) feedback on the patch. Thank you again.
Comment #117
kristen polConfirmed that the interdiff in #111 covers the feedback from #110. Thanks!
Remaining item from #110:
Comment #118
wylbur commentedThe patch file in #111 not applying to 8.9.15, which was released today.
I wish I had time to re-roll this today, sorry!
Comment #119
neclimdulThat makes sense. #111 targets the latest version of Drupal and contains changes to a file added in 9.1.x (cspell/dictionary.txt). You'd need a patch prior to #108 to apply it to earlier versions of Drupal.
Comment #120
anybodyJust tried #111 on 9.1.8 and it works great on content type layouts (/admin/structure/types/manage/page/display/default/layout) but the link doesn't appear at all on node layout overrides (node/xxx/layout)
Comment #121
anybodyPatch #111 seems to need a reroll for 9.3.x and 9.2.x plus my problem in #120 (link not appearing at all)
Comment #122
darkodev commented9.2.0 using patch #111 fails on dictionary.txt because terms have been added. This seems like a moving target since terms seem to be added regularly. I added 'fieldnid' manually.
fieldnames
+ fieldnid
fieldsets
After that change, this patch does show the "Control visibility" link on blocks at node/xxx/layout for us. Not sure what's stopping it from working for @Anybody.
Comment #123
anybody@darkodev thank you very much for your confirmation. Then it seems to be a problem only in my case. It's a simple blog using Olivero with Drupal 9.2.0. I'll have a deeper look asap. So don't consider my comment as blocker, then. The functionality is important.
Comment #124
pixelwhip commentedHere's a reroll of #111, fixing the issue in dictionary.txt.
Comment #125
meenakshi_j commentedFixed the #124 fails.
Comment #126
didebruThanks for the patch!
We have the following issue on a multilingual site.
https://drupal.stackexchange.com/questions/304056/how-to-add-language-pr...
In short:
when default language negotiation and source language differ we get a 403 response.
Because the action link does not have a language prefix.
So the solution for us is to hook into that:
Also patch 125 is not compatible with 8.16.0
Have a nice day and best regards
Comment #127
didebruChange to needs work for the language context issue.
Comment #128
grayle commentedIgnore this patch, it's 111's patch but with modal instead of off canvas. Speaking of, any chance this patch can be created so people can alter if it's off canvas or modal, etc. We're using https://www.drupal.org/project/layout_builder_modal with some extras in hook_link_alter, and it's a fairly popular module.
Comment #129
meenakshig commentedComment #130
meenakshig commentedComment #131
suresh prabhu parkala commentedA re-rolled patch against 9.3.x. Please review.
Comment #133
bnjmnm@Suresh Prabhu Parkala re #131 there's no need for a re-roll against 9.3.x, there's a patch applying successfully against 9.3 in #125 . You were making changes to patch #128, which explicitly said ignore this patch, so there's no need to reroll.
To mitigate this confusion, I've changed this to a merge request based on #125.
Re #128 @Grayle
This issue is about Layout Builder block visibility conditions - incorporating such a change here would be out of scope, but you could create a new issue requesting this feature. If your primary interest in having these forms as modal is the available width, you can also drag the off-canvas dialogs to resize them wider (although this does have to be done every time they open, it wouldn't change the default width).
Comment #134
dmitriy.trt commentedIt looks like current approach doesn't allow a condition plugin to use AJAX on its configuration form. Just because the form is rendered on a route where it doesn't exist here. And it's also the reason why its
#actionhas to be rewritten here.An alternative would be to list condition types as AJAX-enabled URLs instead. This way there must be no issue with AJAX on the condition settings form.
Comment #136
dmitriy.trt commentedSubmitted an alternative MR !1148. The issue it resolves is described in #134.
Another option is to make a sub-request to the form route. This way AJAX should also work on the condition form.
Comment #137
luke adams commentedI think another very useful set of functionality here would be for empty vs non-empty node fields.
ie. If node_type:field_a is empty, do not render this block, and if node_type:field_a is !empty, do render this block.
Comment #138
justcaldwellI believe #137 can be accomplished with Entity Field Condition.
Comment #139
anybodyI agree and think #137 is off-topic. @ZhuRenTongKu please create a separate issue for that, if you think it's helpful and Entity Field Condition can't solve it. Let's focus on this issue.
Comment #140
luke adams commented@justcaldwell good call, I'll check that out, thanks!
@Anybody, I'll check out Entity Field Condition, seems like it may solve my issue. I did write some code that allows me to do the behavior I mentioned, for both sections and blocks. However, it's a wee bit crude as it only allows for one condition per section/block, naturally as soon as I wrote it I came across the need to have multiple conditions on the same section/block!
@danflanagan8, Thanks for the plug on the Boolean module, perhaps there's an opportunity to collaborate on it!
Comment #141
dmitriy.trt commentedAdding a diff file here for a stable reference from composer files. It was made from MR !1148 at commit
972afa7c.Comment #143
didebruWe noticed an issue that the condition operator is not transfered from the BlockVisibilityForm to the ConfigureVisibilityForm.
We could add an optional parameter to the layout_builder.add_visibility route with "and" as default.
I tried this and this seems to work.
Comment #144
didebruThis patch only includes the missing operator parameter.
Comment #145
darkodev commented@justcaldwell, @Anybody, @ZhuRenTongKu
Entity Field Condition would be a very good solution, but it seems to cause an AJAX error when used with patches in this thread. I created a feature request https://www.drupal.org/project/entity_field_condition/issues/3248365
Comment #146
yogeshmpawarRe-roll of #144 against 9.3.x branch.
Comment #147
damontgomery commentedWe've used #144 recently with a custom condition plugin. Haven't tried #146 yet, but the general approach makes sense and seems to work for us.
Thanks.
Comment #149
liquidcms commentedI agree with @darkodev that block visibility based on field values would seem like a very common use case; but as pointed out it fails due to it's ajax loading of fields. Most likely that is tied into this feature not being able to currently support that.
Comment #150
liquidcms commentedFound this 3 patch set from here: https://www.drupal.org/project/entity_field_condition/issues/3091898#com... (comment #20) to work to provide field value based block visibility control within LB.
Comment #154
rkelbel48 commentedHey all, I was running into migration issues with Panelizer and ran across this issue. This visibility is highly needed for Layout Builder to be a Panelizer replacement in D9 for migrations. How close are we on this current issue?
Comment #155
miiimoooConfirming this works. One caveat, for existing layouts I don't get the "Control visibility" in block context menus. It's only if I move them to a new section that the menu item is added below "Remove block".
Another obvious problem is that layouts using this patch will break if the patch is removed - e.g.
Just leaving this here for future reference.
Comment #156
anruetherI can't confirm this. For me the visibility control also appears for blocks that are inside sections that were added before the patch was applied.
Comment #157
nrogers commentedI can confirm the caveat in #155, "Control visibility" doesn't show up for me on a page where blocks were already placed until I move the block to a new section or remove and re-add the block. However, it did work on another page where there was only one section present.
Comment #158
chris burge commentedRe new contextual links not displaying for existing content, this is a known core bug: #2773591: New contextual links are not available after a module is installed.
Comment #160
rahaf albawab commentedThe patch didn't work for me
I add block from block layout and hide it from the home page when i edit the layout builder the block appears on the backend
Comment #161
crutch commented+1 #154, subscribe
Currently working on 2 versions of the same site d9.4.8, 1 with Panels, 1 with Layout Builder.
Comment #164
hfernandes commentedI've fixed the MR https://git.drupalcode.org/project/drupal/-/merge_requests/2537
Also attaching the generated patch for Drupal 9.5 here.
Comment #165
mark_fullmerHere's a re-roll of #164 that applies to Drupal 10.1.x; I did not attempt to fix the failing tests.
Comment #166
chikePatch #165 applied on Drupal 10.0.3 but clicking on 'Control visibility' does nothing but log this error,
Error: Call to undefined method Drupal\layout_builder\Form\BlockVisibilityForm::getAvailableContexts() in Drupal\layout_builder\Form\BlockVisibilityForm->buildForm() (line 124 of /home/project-root/public_html/core/modules/layout_builder/src/Form/BlockVisibilityForm.php).Comment #167
mark_fullmerLooks like the error above is due to the change in #3099968: Layout builder incorrectly resolves global contexts values when viewing layouts.
The attached patch resolves that. This functionally works in D10, though I haven't addressed any of the test issues.
Comment #168
chikeYippee! Patch #167 is working. Thank you @mark_fullmer
Comment #171
rpayanmTrying to fix the failures.
Comment #172
liquidcms commented#158 suggests that a patch allows the contextual link for this work to show on existing blocks. It does not fix it for me.
Comment #173
kevinquillen commentedI just stumbled across this thread. I wound up creating a module before I saw this (I deal with the Context module a lot more for this sort of thing):
https://www.drupal.org/project/layout_builder_context
Comment #176
dinazaur commentedI'll try to arrange current state of issue.
As per #126, we don't have a translation for LB in the core, I tried the asymmetric translation contribute module, and even with this it works as excepted.
#155 - This one was already fixed once for removing, and updating context menus. All we need to do is to add another operations key here
Merge request !3627 is missing Ajax fixes from this PR https://www.drupal.org/project/drupal/issues/2916876#mr1148-note42005
Same thing for 2916876-167.10x.patch it does not contain Ajax fixes from MR.
Apart from that, I didn't find any other "blockers". Could someone clarify why we cannot move this issue forward?
Comment #177
jive01 commentedSorry folks, I can't tell. Are any of these patches working for 9.4 ?
Comment #178
jive01 commentedSorry! Did not mean to switch version numbers.
Comment #179
vasikeTests fixed ... so Let's review to see what's "left behind".
maybe some things could be added on a follow-up issue, if not "critical" for the solution.
Comment #180
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #181
vasikeit seems the MR for 10.1.x has conflicts with 11.x
Let's try with a patch file for 11.x
Comment #182
dinazaur commentedBut none of my points from #176 were fixed
1.
As I can see there is still
2.
As I mentioned in #176 we need to add
operationsso the client side will clear the cache for contextual links.Comment #183
vasike@dinazaur
i don't think the link is correct
https://www.drupal.org/project/drupal/issues/2916876#mr1148-note42005
could you provide the right one?
maybe commit link or some other gitlab change link/url ...
Comment #185
vasikelet's "regain" some attention. as the last questions didn't get some answers.
Comment #186
dinazaur commentedHello @vasilke
1148 PR uses LayoutRebuildTrait::rebuildAndClose method, instead your PR contains 'workaround' that is not needed at all.
And still, my second point from #182 was ignored.
Comment #187
vasike@dinazaur
(previously) i only took the latest MR and made it "green".
I wasn't aware that a previous MR has some "extra fixes".
(Now) I updated the MR including the extra commits from !1148 MR
But those changes actually changed the UX/UI for this feature, so the tests were broken.
So i updated the tests ... to pass, but without changing what's tested.
Still not sure about the solution, as there were a lot of patches and MRs, but not really. a plan. maybe a "core maintainer" could lead things here.
But for now i think we're good to review again - temporary.
p.s. also added "Needs issue summary update" tag. as i think we need to have clear info about what are we're trying to achieve.
Comment #188
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #189
vasikeLet's try with a patch file for 11.x with latest MR updates
Comment #190
smustgrave commentedMoving to NW for change record and issue summary update mainly.
But applied the patch and may see a bug. For sites already with layout builder and blocks placed the visibility contextual link does not appear.
Cleared cache numerous times but no luck.
If I readd an existing block then it appears.
Comment #192
codebymikey commentedFollowing the #146 patch, #167 breaks behaviour such that the context is no longer passed through to subforms.
This is related to the https://www.drupal.org/node/3195121 change record, and the new code should be making a call to
$this->getPopulatedContexts($section_storage)rather than$this->contextRepository->getAvailableContexts($section_storage).Comment #193
gauravvvv commentedPatch #192, no longer applies, attached patch for D11
Comment #194
gauravvvv commentedComment #195
jive01 commentedSorry folks, I can't tell... Is this no longer going to be planned to implement on D9? I see. mainly patches for D10 - D11... It's quite a long thread so I 'm not sure which patch I can implement...
Comment #196
smustgrave commentedSomeone may post a patch but D9 is EOL so no more releases.
Comment #197
crutch commentedI tried 194 on 10.1.6 core-recommended yesterday but it didn't apply. Hopefully once it passes for 11 then one for 10 will be made. 11 is so far out from now.
Comment #198
pyrello commented@crutch - just a small point of clarification:
11.xis essentially the currentmainbranch all development. Since the current cycle is still targeting 10.x releases, those get created from the 11.x branch.https://www.drupal.org/about/core/blog/new-drupal-core-branching-scheme-...
Comment #199
liquidcms commentedIs it just this patch required for this? Read (way) above that there might be a context patch also required (but if that was the case it would likely be mentioned in the OP).
I have D10.0. The patch from #192 is the most recent which applies. The functionality is there so far as the Control Visibility contextual link is there. Opening it (now) gives me a list of plugin options (it used to be a selector). Selecting Node Field and i get a constantly spinning throbber with what looks like the right form:
- node type (it doesnt know i am on LB for a specific bundle)
- Field
- value source
- etc.
When i pick my node type, the throbber stops but the Field field disappears.
Is it possible this part is simply not supported by core (which would be silly of course as fields are core)? I was previously using a patch to the Entity Field Condition module (i suspect in conjunction with the work here) and that patch is no longer compatible with D10; so i removed it thinking possibly covered by the work here.
Comment #200
webdrips commented#192 and the Entity Field Condition module with this patch work for me on D10.1.6: https://www.drupal.org/project/entity_field_condition/issues/3091898#com...
Comment #201
neclimdulThis isn't in the patch? Why is it getting added?
This relies _very_ heavily on the render order. Is that a problem? What happens when modules mess with the render order? Can we make this more resilient or move it down a layer?
- UI is ugly? Don't know if this is something with my admin theme but all the components are on the off canvas overlay but they're hard to understand and interact with.
- Adding visibility closes the entire off canvas area instead of returning to visibility control. This makes it quite awkward to make multiple changes or even confirm your changes where done correctly.
- Sometimes we say control visibility, sometimes we say configure visibility.
@vasike earlier you mentioned questions not getting answered. Are those still relevant? Can we recapture any outstanding issues in the IS?
Comment #203
amarlataFixed: undefined method issue
Error: Call to undefined method Drupal\layout_builder\Form\BlockVisibilityForm::getAvailableContexts() in Drupal\layout_builder\Form\BlockVisibilityForm->buildForm() (line 125 of /core/modules/layout_builder/src/Form/BlockVisibilityForm.php).
Comment #204
amarlataFixed: undefined method issue
Error: Call to undefined method Drupal\layout_builder\Form\BlockVisibilityForm::getAvailableContexts() in Drupal\layout_builder\Form\BlockVisibilityForm->buildForm() (line 125 of /core/modules/layout_builder/src/Form/BlockVisibilityForm.php)
Comment #205
amarlataComment #206
crutch commentedThanks for everyone's work on this, I've been following this thread since starting work on D7 > D10 in 2021. Visibility can be controlled in other ways, should it be major? Though, it would be nice to have this for core blocks and it was the first thing I looked for when moving to layout builder. It was the way to do it in D7 with panels so it was natural to look for this functionality.
We went live with a few sites on D10 July 1, 2023 without it. For core blocks like Body, we recreated them as a View block and then we have control. There are a few blocks where we are using BVG. I understand the need though, easier and more intuitive to have the functionality within.
Now that we aren't using or needing it, having visibility control conditions for blocks within layout builder may be something that could be disabled as a setting or that could be a separate module?
Comment #207
damienmckennaPatch #205 didn't apply cleanly to 11.x, so this is a reroll.
Comment #208
marysalome commentedI just updated to 10.2. We have layouts where we controlled visibility using a patch ("https://www.drupal.org/files/issues/2023-03-10/2916876-167.10x.patch"). This patch doesn't work with Drupal 10.2 and impacts display in a profound way on a large site.
Are any of the recent patches compatible with 10.2?
Update: 207 works on 10.2. The existing visibility rules are being applied, and I see the toggle for setting visibility on new blocks.
Comment #209
smustgrave commentedShould be converted to an MR.
FYI 11.x is the current development branch.
Moving to NW for CR.
Comment #211
joseph.olstad@smustgrave, the MR is trying to merge to 10.1.x, should be a merge request for 11.x
with that said, I took what I could from 207 and brought it into MR 3627
Comment #212
solideogloria commentedThe MR is targeting 10.1.x. I don't know how to rebase it for 11.x. When I click "rebase" on the MR, nothing happens, so I must not have access.
Can someone do that, please? @smustgrave?
Comment #213
solideogloria commentedAlso, #207 does still apply cleanly.
Comment #218
d70rr3s commentedRebased from 11.x into 2916876-11.x, but not getting the MR button on the issue page
Comment #220
jlbellido@d70rr3s make sure you are logged in on GitLab. Sometimes when you access there it is done as anonymous and therefore you don't see the MR button.
I hope it helps.
Comment #221
solideogloria commentedIt says the MR contains no changes.
Comment #222
d70rr3s commentedSorry, for some reason I read the git log wrong and thought I pushed the new branch.
Comment #223
farnoosh commentedPatch #207 has the warning for deprecated code: Deprecated function: Creation of dynamic property Drupal\layout_builder\Form\ConfigureVisibilityForm::$classResolver is deprecated in Drupal\layout_builder\Form\ConfigureVisibilityForm->__construct() (line 123 of /code/web/core/modules/layout_builder/src/Form/ConfigureVisibilityForm.php)
https://www.drupal.org/node/3428661
I am not sure about this patch. I remove the deprecated class. Please give it a test.
Comment #225
socialnicheguru commentedpatch #223 left out new files
Comment #226
socialnicheguru commentedComment #227
vasikeI created new branch for 11.x as the previous one seems not clean enough ... it contains other commits ...
https://git.drupalcode.org/issue/drupal-2916876/-/tree/2916876-add-visib...
Also included some fixes for CS, PHPStan, CSS ...
However it seems the drupal gitlab doesn't like this branch
There are issues creatina and running pipelines and also latest failed to create new MR
https://git.drupalcode.org/project/drupal/-/merge_requests/7501
I'm putting on Needs Review as the MR should be (created and ) Green.
Comment #230
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #238
vasikeIt seems the gitlab it's back in business.
But the latest MR for 10.x got "dirty" from the mix of patches and MR updates attempt ... this means also the new 11.x MR is not in the "best shape".
So for start we need to review again all the updates and put it back on track.
Comment #239
vasikeI updated the MR
- Revert BlockVisibilityForm to ajax button version as tests expected
- And some cleanup
So, we should have an 11.x MR working ... which should be used for the solution
Also hiding all the patches. We should work only on the current MR.
Unfortunately the mix of patches (mostly without interdiff) and MRs "slowed down" the progress here ... imho
Comment #242
smustgrave commentedHiding patches
Left some comments on the MR.
Haven't seen "Needs design" before but sounds like usability.
Tagging for issue summary as the User interface changes should contain screenshots of the changes.
Comment #243
vasikeI tried to address the threads and also applied the suggestions.
Unfortunately I can't run FunctionalJavascript tests locally on 11.x ...
For the other things maybe there will be someone to help here.
Comment #244
solideogloria commentedIf you use DDEV, you could try using ddev-selenium-standalone-chrome to run the tests locally. I've never used it, but it's something you could try.
Comment #245
tim.plunkett`needs design` literally means that it needs a designer. Which is different than usability.
I don't know that a UI designer ever looked at this, as opposed to solely front-end and back-end developers.
Comment #246
smustgrave commentedDo you have a suggestion for a designer? Don't see anything in the MAINTAINERS file and it was originally tagged 5 years ago for one so not sure a random designer knows to look?
Never seen this tag just don't want it to be an unmovable blocker
Comment #247
solideogloria commentedNo, sorry. I just thought that a "D8" related tag didn't make sense, and there was no D11 replacement. It'd be helpful if tags had descriptions or usage guidelines, similar to Stack Exchange.
Comment #248
anruetherWhen using #207 or MR from #243 with 10.3 and the new experimental navigation module, I get a WSOD.
Drupal\Component\Plugin\Exception\ContextException: Assigned contexts were not satisfied: user in Drupal\Core\Plugin\Context\ContextHandler->applyContextMapping() (line 145 of /home/andi/git/site-h4d-greenopolis/web/core/lib/Drupal/Core/Plugin/Context/ContextHandler.php).See full backtrace in #3458973-2: Visibility control not working for navigation blocks
Comment #250
milos.kroulik commentedFYI: There's now a module which claims to provide this feature until this is merged: https://www.drupal.org/project/conditional_rendering
Comment #251
joelpittet@milos.kroulik we tried conditional_rendering and it doesn't seem to solve what this issue is trying to solve. It also only works for block_content so not other block types, or simple_block for example.
Comment #252
joelpittetAdding tag back from #245 as it I think it was accidentally removed.
We tested MR7501 and it will solve our immediate requirement.
Comment #253
andypostadded 2 suggestions for PHP 8.4 compatibility
Comment #255
vasikeMR updates:
- Updated with the latest 11.x branch - as there were some "deprecated" Tests failures + not losing the track
- Solve PHPCS / PHPStan / cspell (new) errors reported.
- Closing old threads - updates/changes already committed for them.
However there are some failures for Tests, but doesn't seem related with the MR changes/updates.
Any news about a "Designer" to look into this ... So we could also do the other Updates: MR updates, Summary Updates and Change Record(s).
Comment #256
wrd-oaitsd commentedDoes anyone have a version of this patch that applies successfully to 10.4.2? Until a couple of days ago, I was using the 7501 diff with 10.4.1 successfully, but composer is now rejecting it.Nevermind -- I see now that I should be using 7497.
Comment #260
pavel ruban commentedTested with 10.4.3
@see https://www.drupal.org/project/entity_field_condition/issues/3091898#com...
Comment #261
pavel ruban commentedThis is correct patch for 10.4.3, please ignore above (composer issue)
As an overview of https://git.drupalcode.org/project/drupal/-/merge_requests/11307#note_47...
What is this about:
Conditions are plugins, they use form api, form api is a powerful tool to handle different scenarios like multistep forms or forms with elements using ajax which allow you to rebuild form depending on context values or submit data without page reload. As conditions are plugins and should allow this type of things as they use form api we need to support this feature, it's a vital question for modern and user friendly interfaces and UX.
How it was:
Now about visibility rules - it's a multistep form that renders second configure form on next stage which renders plugin settings form as subform and all this happens in context of first block visibility form. As a result all ajax features of condition plugins are broken and all not plain / dummy condition forms (using only immediate inputs) that try to use rebuild or ajax possibilities are completely broken.
What was tried before:
This was attempted to be fixed via breaking multistep multiple forms jail and move condition selection to the plugins list which rendered separate condition forms in a modal using plugins own form routes which allowed all form api features, it was done here: https://git.drupalcode.org/issue/drupal-2916876/-/commit/8b6906913c54430..., I think it's not a friendly UX to have all plugins as a list but it was fairly a straight forward fix and did the job, later it was reverted back to initial multistep design which returned better UX but again broke all form api features here: https://git.drupalcode.org/issue/drupal-2916876/-/commit/307baed57592936...
Ctools plugins management logic had the same issue and was solved here: #3230847
Current state:
In an attempt to fix this and preserve multistep plugin selection UX I made a patch to proxy ajax plugin settings form activity to the second stage configure visibility form as a symphony http sub request and handle all ajax and rebuild processes and ajax response subscriber and ajax callbacks / submits stuff in a normal form api environment, once done return result as ajax response back to host block visibility form and proxy it as hidden ajax submit condition settings rebuild handler with it's own ajax callback. It works, concerns are welcome. You can check the approach here: https://git.drupalcode.org/project/drupal/-/merge_requests/11307/diffs?c...
Comment #262
flyke commentedNo MR seems to apply to D11.2.0
Comment #263
waropd commentedPatch that applies to 11.2.2
Comment #264
lawxen commentedWith navigation enabled, Error with patch of #263 on Drupal11.2.2
Class "Drupal\layout_builder\EventSubscriber\SectionComponentVisibility" used for service "layout_builder.component_visibility_subscriber" cannot be found.Comment #265
prashant.c@waropd
Thanks a lot for the patch you provided, in the initial testing seems to be working fine on our 11.2 instance. Hopefully will get stable patch for this.
Comment #267
eelkeblokI updated MR 7501 for D11.3, only to afterwards realize there is a different approach available in MR 11307. I don't have enough understanding of the code at this point to understand which approach is superior.
Comment #269
jay.silverman commentedSee attached patch which contains changes from "MR 7501 for D11.3" with additional changes to be compatible with D11.3.2. Note: It doesn't include the phpstan changes from MR 7501 which also require changes.
Comment #270
steffenrThanks for working on a patch to get the visibility plugins into layout_builder.
Unfortunately the patch is not working, if you display fields within the layout_builder layout.
While using fields we get a block of type
Drupal\layout_builder\Plugin\Block\FieldBlock, which leads to an error within the title callback of BlockVisibilityForm.AssertionError: assert($block instanceof BlockInterface) in assert() (line 280 of /var/www/html/web/core/modules/layout_builder/src/Form/BlockVisibilityForm.php).Comment #272
jay.silverman commentedSee attached patch. This is an update to the patch from #269. The "assert($block instanceof BlockInterface);" has been removed from the "title" function in core/modules/layout_builder/src/Form/BlockVisibilityForm.php. Thank you @steffenr for the heads up on the assertion error.