Just like in D7, the D8 version of Page Manager should allow the specification of optional arguments. Currently, any arguments included in the path are required due to the changing of the routing system to Symfony.
I attach a patch with a barebones POC that allows the editor to mark the path argument as optional and page manager then applies a NULL value as a default to that argument in the route.
To fix
- The patch assumes only one argument to be optional. We need to be able to handle multiple arguments, only the last one being optional.
- We need to solve the problem of the context assignment to the context aware plugins (see below the issue)
Ideally, all path arguments should be assigned in the UI to a context (even the optional ones). However, since an argument can be optional, the context might or might not be filled, yet the route will still match building all the context aware components on the page. The patch clears this hydration inside VariantRouteFilter but the blocks for example still get the context due to the caching.
Via PageBlockDisplayVariant, blocks are being built in ::buildRegions()which calls ::getCacheContexts() on the block plugin which ends up calling ContextAwarePluginBase::getContext() which creates and stores a new (empty) context object on the block plugin if it's missing (which it is because we remove it earlier if empty). So we end up with a context on the block plugin with no value or data. Not sure if we wanna do this, but I didn't find another way.
| Comment | File | Size | Author |
|---|
Comments
Comment #2
stborchertModified the patch so you can set the optional-flag for each page parameter (including a simple validation to not have optional parameters before required parameters).
Comment #3
stborchertFixed some errors.
Comment #4
andyg5000@stBorchert thanks for the patch.
The
+=was causing issues for me when parameters were not set (new ones) and throwing a fatal error. Here's an update to the patch that provides defaults for parameters and prevents the error as well as existing undefined index notices.Comment #6
socialnicheguru commentedI am unsure of how to set the path.My use case is group/%gid/page
What is the proper syntax for the dynamic part? Is it %, %gid, or {} as specified here: https://www.drupal.org/project/page_manager/issues/2659948
I think you use the {} syntax now
group/{group}/page
Comment #7
manuel.adanI got this ContextException with patch from #4:
I'm not familiar with page_manager at the development level, but as far I could see, optional argument remains as required in the context definition.
Comment #9
manuel.adanAfter almost 1 year of dealing with page_manager I got fully into the code. Patch reviewed with:
Comment #11
manuel.adanReverses the parameter options logic from "is required" to "is optional" to match the current default behavior that makes tests to fail.
Comment #12
manuel.adanI was getting some undefined index warnings editing argument in existing pages. Re-rolled to the lastest -dev. Interdiff fails, attached simple diff.
Whoever reads this, can you please help in reviewing the patch?. Thank's ;)
Comment #13
berliner commentedPatch applies properly to 4.0.0-beta4 and works as advertised.
Comment #14
saniyat commentedRe-rolled the patch with latest dev. Also, tested with the latest release 4.0-beta5
Comment #15
japerrySince the schema is changing, pretty sure this needs an update.
Comment #16
saniyat commentedRe-rolled the patch with the latest dev. Also, tested with the latest release 4.0-beta6
Comment #17
joel_osc commentedPatch works great for me in 9.1/4.0-beta6, would be great to get this feature added. Thanks everyone!
Comment #18
berliner commentedRe-rolled for 4.0-rc1 and slightly modified to fix UI issues.
Comment #19
ramil g commentedHere's a re-roll of patch #16 for the latest release (8.x-4.0-rc1) minus some doc blocks. If you want to include the doc blocks, please create a new issue for them.
Comment #21
joelpittetHiding @ramil g's patch because it's not passing, thanks for both trying to re-roll this!
I'm glad to see you both removed the docblocks that were added and the main reason this failed. They were a scope creep that we should try to resist but I realize it's hard too, the need to reroll is the consequence of those "clean-ups"
Moving to dev branch.
Comment #22
joelpittetI diff'd the diffs and though some of the changes might be scope creep too I don't think they are to bad if they get in. I'll mark this RTBC in hopes it can get in before needing to re-roll again ;)
Comment #23
ramil g commentedThanks for hiding it Joel, although I do still see my post. I tried to delete it but there's no option to do it.
Sorry @berliner, we both posted less than an hour apart from each other, and I didn't see yours.
Comment #24
joelpittetStrange, the file for #18 doesn't show up in the display. I'll see if I can kick it by hiding all other patches. Sorry @berliner seems to be a bug in d.o
Comment #25
berliner commentedStrange indeed ... Seems so arbitrary :DThat's because it got hidden in #19
Comment #26
joelpittet@berliner, but You should be able to un-hide/display patch files that I hide, that's where I think the bug is.
Comment #28
japerryThanks for everyone's work on this! Committed!