We can set visibility conditions (variant selection criteria) at page and variant level, but it would be nice to apply visibility rules on individual blocks (panes). You used to be able to do this in D7.
There's a patch doing exactly this for Page Manager in #2858877: Allow for block visibility rules. The patch currently being worked on in this issue leverages that. However it currently means introducing a new dependency on Page Manager. Possible solutions:
- Factor the visibility/condition form functionality into core.
- Factor the visibility/condition form functionality into ctools (which is already a dependency of both Page Manager and Panels).
- Make Panels only show/use the visibility conditions if Page Manager is installed (ugly imho).
- Any other ideas...?!
@vbouchet took a different approach in solving the problem by providing a new kind of access plugin for Panels 3.x and 4.x in #11.
Remaining tasks
- Decide how best to share the visibility subform.
- Add tests (might be able to steal from #2858877: Allow for block visibility rules.
Comment | File | Size | Author |
---|---|---|---|
#60 | panels-block_visibility_conditions-2769099-60.patch | 14.59 KB | lobodakyrylo |
#40 | reroll_diff_36-40.txt | 9.81 KB | ocastle |
#40 | panels-block_visibility_conditions-2769099-40.patch | 14.57 KB | ocastle |
Issue fork panels-2769099
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
artreaktor CreditAttribution: artreaktor as a volunteer and commented+1 Would be great to have that feature!
Comment #3
Andre-Bhow would this currently be solved in Drupal 8?
Comment #4
sketman CreditAttribution: sketman commented+1 for this feature. This was an excellent additions to Panels comparing with Display Suite
Comment #5
andypostThis is a regression from d7 - this is must have
Comment #6
dstorozhukUpdate descritition
Comment #7
dstorozhukComment #8
m.abdulqader CreditAttribution: m.abdulqader at Sprintive commented+1
Comment #9
dstorozhukComment #10
vbouchetHi,
Just to let you know that I am currently working on it. You can follow the progress on https://github.com/vbouchet31/panels/pull/1 and will provide a proper patch a soon as the TODO are finalized. This currently works properly (at least what I tested) with Page manager and 8.x-3.x branch of Panels.
TODO:
Comment #11
vbouchetI updated the code mainly to integrate with Panels IPE. It is not perfect (mainly because it currently use the same picto as the configure link - the gear) but at least the Visibility rule settings form is accessible via IPE.
Also, I ported the code to the 4.x branch.
Patch for the 8.x-3.x branch
Patch for the 8.x-4.x branch
The main thing missing now is proper test (as usual ;-) ).
Reviews and feedback are welcome.
Comment #12
AndyF CreditAttribution: AndyF at TES Global commentedIf I understand correctly #11 introduces new panels access plugins; I came here looking for something that integrates with existing condition plugins. (See also #2858877: Allow for block visibility rules in Page Manager.) Here's a first pass at a Panels patch: it needs the patch from #2858877: Allow for block visibility rules.
Feedback welcome, thanks.
Still todo
I'm not marking as needs review because it probably makes sense to wait for the issue in Page Manager to be fixed.
Comment #13
AndyF CreditAttribution: AndyF at TES Global commentedComment #14
drupov CreditAttribution: drupov commentedRe-rolled the patch against the latest dev (Commit dd6e30d on 8.x-4.x)
Comment #15
drupov CreditAttribution: drupov commentedSorry, some code was missing
Comment #16
andypostThere's initial patches for review
Comment #17
millionleaves CreditAttribution: millionleaves as a volunteer and commentedI've applied this patch along with the Page Manager patch.
I've already posted this to the Page Manager issue - sorry for the double posting, but I'm unsure whether it's Page Manager or Panels (or something else) generating the issue.
https://www.drupal.org/node/2858877#comment-12269985
When viewing a node using a Panels variant containing a block where visibility of the block is based on a specified ID, I am now getting this error:
The website encountered an unexpected error. Please try again later.
The server log contains this:
Removing the block visibility rule removes this error and displays the page as it was.
I've tried with the current and -dev versions of both Page Manager and Panels.
Comment #18
drupov CreditAttribution: drupov commentedOK, I reviewed the patch from #15 and there are some methods missing in PanelsBlockConfigureFormBase
Comment #19
swigle CreditAttribution: swigle commentedTried to apply this patch to most recent version of panels publicly available (8.x-4.2). Patching returns the following:
A visual comparison of StandardDisplayBuilder.php and the patch, i see a couple of differences, mainly that my version of this file doesn't mention any \Drupal\Core\Extension\ModuleHandlerInterface being used, but the patch file clearly shows this, although not as a change but as something that should be in the source/base file, which it isnt...
I'm trying to patch in the optional visibility for panel blocks, just like millionleaves is. Page manager patch worked, this one doesnt.
Manually adding the ModuleHandlerInterface kinda works, but when trying to edit a block on a page manager page will give me an ajax error:
Am i using the right version of 8.x- panels? or is something else going wrong?
Comment #20
drupov CreditAttribution: drupov commentedYou should use the latest dev version of 8.x-4.x, currently at commit
9ae218c Issue #2913353 by phenaproxima: IPE attaches behaviors a bit too quickly
Comment #21
swigle CreditAttribution: swigle commentedThanks, that did it!
Checked out latest dev version, and reinstalled page_manager. Ran both patches and cleared cache. Everything seems to be in order now!
Comment #22
TD44 CreditAttribution: TD44 commentedDoes the patch #18 has been commited ?
Comment #23
millionleaves CreditAttribution: millionleaves as a volunteer and commentedThe patch in #18 works for me, but there is a conflict with this patch:
https://www.drupal.org/project/panels/issues/2849867#comment-12431146 - Custom attributes in panels blocks
I've added a comment to that issue which explains how I worked around the conflict:
https://www.drupal.org/project/panels/issues/2849867#comment-12471980
My end goal with these two patches is:
With this resolution I've been able to achieve both.
Comment #24
manuel.adanPatch from #18 uses "Drupal\page_manager_ui\Form\VisibilitySubform". This class:
Comment #25
AndyF CreditAttribution: AndyF commentedJust to clarify, patch from #18 originally came from #12 which states:
Thanks!
Comment #26
manuel.adanThanks for the clarification. So this patch needs #2858877: Allow for block visibility rules from page_manager to work, which, as I said, introduces a new dependency on page_manager. According to the .info file, such dependency currently exists only for tests.
Comment #27
AndyF CreditAttribution: AndyF commentedSorry, in case it was ambiguous I was clarifying that it hasn't been removed. (It was never there in the first place.)
Thanks!
Comment #28
manuel.adanI run into the same as #17:
Patch #2769099-18: Block visibility conditions + #2858877-17: Allow for block visibility rules. Current language as the block visibility condition.
Comment #29
AndyF CreditAttribution: AndyF commentedThanks @manuel.adan - #17 was a cross-post and I updated the patch in #2858877: Allow for block visibility rules as a result of @millionleaves' comment on that thread. Could you try with the latest page manager patch and see if that improves the situation? (If not, if you have time to see if the problem still occurs when using a non-panels page manager page that would be awesome!)
Thanks
Comment #30
manuel.adan@AndyF, I forgot to mention that I tried with [#285877-40], patch applies cleanly in page_manager 8.x-4.0-beta3 (not the latest -dev), but I got a new error when trying to edit a block instance in the panel's content:
so I went back to [#285877-17] and did not go further on this, solving it with another approach in my current project.
Comment #31
AndyF CreditAttribution: AndyF at Fabb commentedThanks for the feedback @manuel.adan.
Hmmn, that's strange, it's applying for me (it's very recent):
Ah thanks! I've been adding tests to the Page Manager patch and it uncovered a dependency that wasn't being injected: the patch on this page will need updating to use that, should be simple to do. I realise it might be a bit late now, but you might have luck with #2858877-27: Allow for block visibility rules which includes the fix to @millionleaves' problem in #17 but is before I started working on the tests.
I'll try to update the patch on this issue soon.
Thanks!
Comment #32
AndyF CreditAttribution: AndyF at Fabb commentedI've introduced a service to decouple the two patches further: this should work with the latest patch in #2858877: Allow for block visibility rules (tested with #2858877-45: Allow for block visibility rules).
Cheers
Comment #33
AndyF CreditAttribution: AndyF at Fabb commentedHere's an updated patch that allows conditions to be set on contexts from the panel, works with #2858877-52: Allow for block visibility rules.
Comment #34
millionleaves CreditAttribution: millionleaves as a volunteer and commentedThanks @AndyF - I can confirm that the patch in #33 works with #2858877-52: Allow for block visibility rules, and does (almost) what I need to in terms of setting block visibility in Panels. The only thing missing is the option to set multiple Visibility Rules (as in Panels 7) but I'll leave that for another issue ;)
Note that the issue I reported in #23 still exists, but I've found that if you apply this patch first, and then the Custom Attributes patch then it is relatively easy to resolve the conflict manually, as documented here:
https://www.drupal.org/project/panels/issues/2849867#comment-12703972
Hopefully one of these two patches will get committed soon so the other can be re-rolled against it.
Also, it's worth noting that if you install this module as well, you'll also get the option to set visibility based on the value of a node field:
https://www.drupal.org/project/entity_field_condition
You'll also get the option within Page Manager to use a node field as a Variant selection rule.
Comment #35
drupgirl CreditAttribution: drupgirl commentedPatch #33 works for me. Thank you very much.
I did notice that I could not isolate only authenticated users because I could not negate user role condition for block visibility. I ended up using panels and blocks in regions with this patch to return negating function to D8.
Not sure why this functionality was removed, but it would be good to have here, as well, imo.
Comment #36
artematem CreditAttribution: artematem at FFW commentedUpdated patch to roll on 4.x-dev module version.
Replaced
Drupal\user\SharedTempStoreFactory
withDrupal\Core\TempStore\SharedTempStoreFactory
Comment #37
manuel.adanThis introduces a circular dependency on page_manager, which also depends on panels. I didn't go further after this point.
Needs test coverage.
Comment #38
AndyF CreditAttribution: AndyF at Fabb commentedThanks @manuel.adan
I don't think page_manager depends on panels. However I'm not convinced adding the dependency is a good idea nonetheless. See the IS for a description of the dependency issue (also point 2 in #2858877: Allow for block visibility rules IS) with some possible solutions.
Comment #39
manuel.adan@AndyF, that's true, I was reviewing some ctools issues just before got here and I still had its dependency in mind. Nevertheless, and as you pointed, it would be preferable to avoid dependency on page_manager in this case.
Comment #40
ocastle CreditAttribution: ocastle at Full Bundle commentedRerolled Patch from #36
Comment #41
liquidcms CreditAttribution: liquidcms commentedtried this patch.. of course difficult to tell what it applies to but i grabbed latest -dev and it almost applies cleanly; i manually fixed the part which didn't.
trying to edit a page in panels and i now wsod with:
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "page_manager.condition_access_resolver". in Drupal\Component\DependencyInjection\Container->get() (line 153 of core/lib/Drupal/Component/DependencyInjection/Container.php).
Comment #42
ocastle CreditAttribution: ocastle at Full Bundle commentedRe-rolling patch and removed the page_manager dependency
Comment #44
ocastle CreditAttribution: ocastle at Full Bundle commentedRe-rolling patch. Added back in page_manager dependency - misinterpreted the above.
Comment #45
ocastle CreditAttribution: ocastle at Full Bundle commentedComment #47
NWOM CreditAttribution: NWOM commented#44 worked great in combination with #2858877: Allow for block visibility rules. Thank you!
Comment #48
Sseto CreditAttribution: Sseto commentedHey guys,
I tried to apply 2 different patches for Panels and I'm getting an error.
Patch 1: [Block visbility conditions](https://www.drupal.org/project/panels/issues/2769099)
Patch 2: [Allow for block visibility rules](https://www.drupal.org/project/page_manager/issues/2858877)
`https://www.drupal.org/files/issues/2020-07-13/panels-block_visibility_c... (Block visibility conditions)`
`https://www.drupal.org/files/issues/2020-04-30/panels_custom_attributes_... (Custom attributes in panels blocks and variants)`
`Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2020-04-30/panels_custom_attributes_...`
I tried swapping them around and still the same error.
The weird part is that Both patches are somehow still applied and working.
*EDIT: The UI to add `style settings` in https://www.drupal.org/files/issues/2020-04-30/panels_custom_attributes_... is showing, but it actually doesn't add the CSS classes.
Comment #49
Sseto CreditAttribution: Sseto commentedHey everyone! I was able to figure it out. I wrote my steps on the other issue https://www.drupal.org/project/panels/issues/2849867#comment-14001266
Comment #50
NWOM CreditAttribution: NWOM commented@Sseto: Here is a patch that already combines both patches in case you want to add it to composer: #3183258: Block visibility conditions and Custom attributes combined patch for composer.
As a summary, the patch in this issue works, however it is incompatible with the Custom attributes patch, until one gets committed and the other patch gets re-rolled. As a workaround, the combined patch that I created can be used.
Comment #51
crutch CreditAttribution: crutch commentedApplied both patches with the latest 4.x-dev for page_manager and panels.
Located these items below in conjunction with the patches, it works for conditionally hiding blocks based on term selection in Page variants.
https://www.drupal.org/project/block_visibility_groups
https://www.drupal.org/project/term_condition
Great thank you!
Comment #52
Sseto CreditAttribution: Sseto commentedI recently migrated my D7 site to D9 and the site has this error now:
InvalidArgumentException: You must provide the context IDs in the @{service_id}:{unqualified_context_id} format. in Drupal\Core\Plugin\Context\LazyContextRepository->getRuntimeContexts() (line 71 of core\lib\Drupal\Core\Plugin\Context\LazyContextRepository.php).
As soon as I add a new block into a region, I get it...
Any idea what could be the issue?
Comment #53
crutch CreditAttribution: crutch commentedAfter the latest updates for page manager and panels, and removing these two previous patches from composer because they should be integrated now, then block visibility is gone and unavailable when editing a block in panels. No errors.
https://www.drupal.org/files/issues/2020-06-24/page_manager-block_visibi... (2858877: Allow for block visibility rules)
https://www.drupal.org/files/issues/2020-07-13/panels-block_visibility_c... (2769099: Block visibility conditions)
Comment #54
Sseto CreditAttribution: Sseto commentedI'm also having the same issue as crutch after the new updates. Anyone know what's going on?
Update: Got it working. Thanks for the patch NWOM!
Comment #55
crutch CreditAttribution: crutch commentedHi Sseto, what recipe of module versions and patches did you use to get it working again? For some reason, I'm not able to get the visibility conditions back. Thank you, Crutch
Comment #56
Sseto CreditAttribution: Sseto commentedHey Crutch, You should try and use this patch: https://www.drupal.org/project/panels/issues/3183258
Comment #57
crutch CreditAttribution: crutch commentedYes, that is the solution, thank you!
Comment #58
lobodakyrylo CreditAttribution: lobodakyrylo as a volunteer commentedRerolled Patch from #44
Comment #60
lobodakyrylo CreditAttribution: lobodakyrylo as a volunteer commentedThe previous patch contained issue
Comment #61
joseph.olstadComment #62
joseph.olstadexpecting 1 fail from HEAD
#3383474: Fix HEAD test failures for 4.x
Comment #64
joseph.olstadThe latest patch #60 introduces 9 new test failures.
see
#3383474: Fix HEAD test failures for 4.x
we only have 1 head failure currently, and looking to fix that.
Comment #65
renatog;
Comment #66
renatogAware that #60 needs works according to comment above
On this meantime, for any reason if someone needs to use on 8.x-4.7 tag, this is the patch
P.S. Making as hidden since tests needs to be done development branch