Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
The Views widget allows providing parameters of the original path as arguments to the displayed view. This feature has been added in #2400435: Allow additional parameters to be passed to widgets but is not yet reflected in the UI.
Proposed resolution
Provide an optional setting on the widget form to set the arguments.
Remaining tasks
Review the patch, add tests.
Comment | File | Size | Author |
---|---|---|---|
#19 | entity-browser-views-widget-arguments-option-2832240-19.patch | 2.75 KB | josip.rajkovic |
#2 | configure_path_arguments-2832240-2.patch | 1.21 KB | ckaotik |
#4 | configure_path_arguments-2832240-4.patch | 1.77 KB | ckaotik |
#6 | interdiff.txt | 901 bytes | marcoscano |
#6 | 2832240-6.patch | 2.68 KB | marcoscano |
Comments
Comment #2
ckaotikPlease review the attached patch.
Comment #4
ckaotikI have updated the patch to properly handle empty arguments.
I've also added the arguments array to the expected result on the CRUD test. This and the default value for
arguments
should probably have been added in #2400435: Allow additional parameters to be passed to widgets, but better late than never :)Comment #5
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedThank you! Patch looks good to me. Would be nice to add some test coverage though.
Comment #6
marcoscanoRe-rolled and added the missing assertion.
(by the way, I assume the missing test was just for the UI addition, not for the functionality itself :)
Comment #7
Mirroar CreditAttribution: Mirroar at werk21 commentedRerolling against the current version.
Comment #8
netw3rker CreditAttribution: netw3rker commentedI'm bumping this up to 2.x since it applies cleanly, and that appears to be where all the modern development for this is heading.
Comment #9
oknateThe patch still applies to the 8.x-2.x branch after the removal of ctools ui.
Here's a screenshot of the ui for the widget config form with this new field:
The validation works well, uses javascript.
It saves to the config fine.
The schema looks right for integer only arguments.
Here's one odd thing, when you remove the arguments and resave, it saves an empty arguments array where there was none before:
Here's it in action, and this took me by surprise. The arguments are not integer arguments to the view, but rather integer arguments that map to parts of the path. I was testing with an entity embed, so this is what I got:
This is interesting because in this context, I would think it might be more useful to have the original node's node id, if available.
This is where this gets problematic. If you have it on an entity reference field, it would only work once the node is saved, I would think. Otherwise, node/add/article, you'd get "add", where you might want to pass the node id to the view.
I don't remember how views behave, but I wouldn't be surprised if it's expecting an integer (from node/1234/edit) and it gets an a string from node/add, it would throw an error.
I think the help next needs to be clearer that you're adding parts of the path from the page that launches the entity browser.
Also, we need test coverage for this form as well as the behavior of the view widget plugin pulling in URL arguments.
Another thing that should be clarified is that the path parts are not zero based. If you want the node id, you'd need to put 2, instead 1. Which is odd given the history of drupal's arg() function and how many things in programming are zero based.
Comment #10
oknateComment #11
oknateComment #12
oknateComment #13
Primsi CreditAttribution: Primsi at MD Systems GmbH for MD Systems GmbH commentedComment #14
oknateI have some code in a related issue that would return the original path in both the context of a field widget and an entity embed. See https://www.drupal.org/project/entity_browser/issues/2790951#comment-129...
I think we could probably combine the two issues. That patch adds a hook that allows altering the view (including the arguments) before rendering.
Comment #15
oknateComment #16
oknateReroll of #7 only.
Comment #17
oknateAfter testing again, I think this approach makes less sense than 2865928 and 2790951.
Url argument path parts are more fragile than getting target_bundle and original entity route.
Even though the module supports url path part conversion to arguments already, I don't think this is the most stable way to get context to the view.
Comment #18
oknateComment #19
josip.rajkovic CreditAttribution: josip.rajkovic as a volunteer commentedUploading a reroll of the patch that applies cleanly on version 2.9