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.

Comments

Upchuk created an issue. See original summary.

stborchert’s picture

Version: 8.x-1.x-dev » 8.x-4.x-dev
StatusFileSize
new6.44 KB

Modified 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).

stborchert’s picture

StatusFileSize
new6.75 KB

Fixed some errors.

andyg5000’s picture

Status: Needs work » Needs review
StatusFileSize
new7.35 KB
new1.11 KB

@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.

Status: Needs review » Needs work

The last submitted patch, 4: page_manager-allow_optional_parameters-2810329-4.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

socialnicheguru’s picture

I 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

manuel.adan’s picture

Status: Needs work » Needs review
StatusFileSize
new7.95 KB
new662 bytes

I got this ContextException with patch from #4:

Drupal\Component\Plugin\Exception\ContextException: The "string"; context is required and not present. in Drupal\Core\Plugin\Context\Context->getContextValue() (line 71 of core/lib/Drupal/Core/Plugin/Context/Context.php).
Drupal\page_manager\Controller\PageManagerController->pageTitle(Object)
call_user_func_array(Array, Array) (Line: 47)
Drupal\Core\Controller\TitleResolver->getTitle(Object, Object) (Line: 743)
token_tokens('current-page', Array, Array, Array, Object)
call_user_func_array('token_tokens', Array) (Line: 402)
...

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.

Status: Needs review » Needs work

The last submitted patch, 7: page_manager-allow_optional_parameters-2810329-7.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

manuel.adan’s picture

Status: Needs work » Needs review
StatusFileSize
new13.89 KB
new8.54 KB

After almost 1 year of dealing with page_manager I got fully into the code. Patch reviewed with:

  • Schema added
  • The required parameter after optional validation moved to the parameter edit form
  • Tests added
  • CS review

Status: Needs review » Needs work

The last submitted patch, 9: page_manager-allow_optional_parameters-2810329-9.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

manuel.adan’s picture

Status: Needs work » Needs review
StatusFileSize
new13.89 KB
new906 bytes

Reverses the parameter options logic from "is required" to "is optional" to match the current default behavior that makes tests to fail.

manuel.adan’s picture

I 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 ;)

berliner’s picture

Patch applies properly to 4.0.0-beta4 and works as advertised.

saniyat’s picture

StatusFileSize
new13.84 KB

Re-rolled the patch with latest dev. Also, tested with the latest release 4.0-beta5

japerry’s picture

Status: Needs review » Needs work

Since the schema is changing, pretty sure this needs an update.

saniyat’s picture

Status: Needs work » Needs review
StatusFileSize
new13.22 KB

Re-rolled the patch with the latest dev. Also, tested with the latest release 4.0-beta6

joel_osc’s picture

Patch works great for me in 9.1/4.0-beta6, would be great to get this feature added. Thanks everyone!

berliner’s picture

Re-rolled for 4.0-rc1 and slightly modified to fix UI issues.

ramil g’s picture

Version: 8.x-4.x-dev » 8.x-4.0-rc1
StatusFileSize
new12.21 KB

Here'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.

Status: Needs review » Needs work

The last submitted patch, 19: page_manager-allow_optional_parameters-2810329-18-reroll-16.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

joelpittet’s picture

Version: 8.x-4.0-rc1 » 8.x-4.x-dev
Status: Needs work » Needs review

Hiding @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.

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

I 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 ;)

ramil g’s picture

Thanks 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.

joelpittet’s picture

Strange, 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

berliner’s picture

Strange indeed ... Seems so arbitrary :D
That's because it got hidden in #19

joelpittet’s picture

@berliner, but You should be able to un-hide/display patch files that I hide, that's where I think the bug is.

  • japerry committed dd4e47f on 8.x-4.x
    Issue #2810329 by manuel.adan, saniyat, stBorchert, andyg5000,...
japerry’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for everyone's work on this! Committed!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.