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.
Very useful module.
Would be a nice feature if you could pass arguments to the selected view.
Especially if we could re-use ctools contexts.
Comment | File | Size | Author |
---|---|---|---|
#22 | ctools_view_acces-pass_views_arguments-2277123-22.patch | 6.67 KB | ndf |
#22 | interdiff-2277123-5-22.txt | 6.54 KB | ndf |
#19 | test_node_panel.txt | 4.79 KB | ndf |
#17 | test_view.txt | 2.64 KB | tripper54 |
#5 | ctools_view_acces-pass_views_arguments-2277123-5.patch | 3.64 KB | tripper54 |
Comments
Comment #1
tripper54 CreditAttribution: tripper54 commentedGreat idea, I'll look into this with a view to add it.
Patches welcome in the mean time!
Comment #2
ndf CreditAttribution: ndf commentedCreated a patch with 3 arguments.
I does its job, but it is not super beautifull.
I have tested it quite thoroughly but would like to know about improvement.
Comment #3
ndf CreditAttribution: ndf commentedComment #4
tripper54 CreditAttribution: tripper54 commentedGreat patch, @nielsdefeyter , thanks for contributing.
I wasn't comfortable with the fixed number of arguments in the form, so spent a bit of time trying to come up with a better solution,
After stuggling in vain with AJAX callbacks to determine the correct number of argument fields to display, I settled on this version, which offers one field for arguments and instructs users to split the arguments with a slash, similar to how the preview works in views UI.
What do you think of this approach?
Comment #5
tripper54 CreditAttribution: tripper54 commented..and here's a version that doesn't break context processing.
Comment #6
ndf CreditAttribution: ndf commentedI agree with you that those fixed arguments are not neat at all.
What I would prefer though (I have been playing around with it but couldn't do it yet) is really use ctools contexts.
This would be trivial if we would know what type of arguments our View needs.
Say the View needs an user-id and a node-id, we could then add:
to the plugin definition and in the settings form nice selects-boxes show up with the real available contexts.
My problem to accomplish that, is that we have to alter the plugin settings after the view has been selected.
2 possible methods:
1. Select a View, extract the View's arguments, add those arguments to the plugin definition.
2. Load the configuration form, load 'all available contexts', add those contexts to the plugin definition as optional. If there are 2 available contexts, you can select 2 arguments. If there are 4 available contexts, you can select 4 arguments.
How do you think about that?
Comment #7
ndf CreditAttribution: ndf commentedLike this one from ctools/plugins/access/context_exists.inc
And this variant with multiple optional contexts.
Comment #8
ndf CreditAttribution: ndf commentedHi Phil,
Think we got a nice patch now!
What is changed since first patch:
- Arbitrary number of arguments.
--- Function 'views_get_view_result' is called with 'call_user_func_array' to make that possible.
- Select dropdowns for arguments selection instead of text fields.
--- Apparently available contexts are known in the settings form.
--- Its impossible now to pass arguments without a context (hardcoded argument). I think this is not a bad thing.
- Code cleanup
--- Moved views options list to '_ctools_view_access_get_views_options_list'.
--- Added arguments to plugin summary.
--- Code commenting, etc.
Comment #9
ndf CreditAttribution: ndf commentedHi Phil, what shall we do?
Comment #10
heivoll CreditAttribution: heivoll commentedJoining the issue here.
I've applied the patch from #8, and it works. However, I noticed that if you use it as a visibility rule on a Panels pane, there are no selectors for arguments.
Also, since the way of using the arguments now are by selecting contexts directly, it's not possible to pass e.g. a field value. That might limit the usability of it a bit. Or am I missing something here?
Sorry for joining in so late. But to be honest, I think the approach from #4 is better, as it gives you the option to use any context and any number of arguments.
Comment #11
ndf CreditAttribution: ndf commentedThanks for your review/feedback!
So the goal of this issue is the ability to pass arguments to a view.
Patch #2 had a fixed amount of arguments and an option for using a context or direct input. Context are recognized by a specific pattern (%node).
Patch #4, #5 has a flexible amount of arguments and both direct input and context. Context are recognized by a specific pattern (%node).
Patch #8 dropped the direct input and favors choosing a context with a select box.
My thought about dropping direct input is that it is more error-prone and user-friendly, because you don't have to remember/lookup available contexts but its just click and go. Feels more ctools/panels-alike.
I am not completely sure, but can't you add a context of type "String" and use its keyword as a substitute for direct input? I will check that within a couple of days.
As of 'visiblity rules'. That's not working, but it should, so could call that a bug.
Comment #12
tripper54 CreditAttribution: tripper54 commentedSorry for my lack of attention on this, hopefully I'll get some time soon to contribute a little more constructively :)
It seems to me that we either:
1. commit patch #5; or
2. work on #8 to address the issues heivoll raises.
TBH I'm OK with either approach. I agree with Niels that a 'click to to configure' option seems like a nicer way to go, as long as the functionality is all there.
I'll leave this with you, Niels, if you would like to keep polishing #8, otherwise let me know and I'll commit #5. I guess the UI could always be cleaned up later, it just adds a bit of fiddling with upgrades...
Comment #13
ndf CreditAttribution: ndf commentedI'll put some time on it this week and then I come back here about it.
Comment #14
heivoll CreditAttribution: heivoll commentednielsdefeyter: Yeah, I guess you're right that it's more elegant and such, and if it can be made to work 100%, it's a very nice solution. It looked first as if it's not possible to use the String context approach, but it should probably be possible with a dev version or something of ctools, see this issue: https://www.drupal.org/node/1774434 . It does have the limit that it's not possible to use token replacements in the string, but that will probably be fixed with time (see the last comments in the issue).
Comment #15
ndf CreditAttribution: ndf commentedHereby the new patch.
@heivoll: the visibility rule setting is fixed with this patch now, but I think the reason it didn't work is a bug somewhere in panels. In the access-plugin definition "all contexts => TRUE" is used, but those contexts are not passed to the settings form. Those contexts are sideloaded now and therefore available.
The string-context is available but not configurable in ctools latest stable release (7.x-1.4). So therefore you need ctools 7.x-1.x-dev today.
I also killed watchdog notices/warnings by better checking for empty arrays/values.
@tripper, heivoll: would be great if you could give this patch another try!
Comment #16
ndf CreditAttribution: ndf commentedComment #17
tripper54 CreditAttribution: tripper54 commentedTo test this, I created a simple view that takes a node ID as an argument, and lists all the nodes with that node id ;)
See attached view.
I then created a panel variant with a string context, name 'string' , value '41'.
I created a custom panel pane on this variant, some arbitary text "If you can see this, the view has returned true".
Added a visibility rule, "a view returns results".
Selected "ctools access test - default" as my view / display.
Now I'm presented with 3 argument dropdowns, even though the view only accepts one argument.
So which should I select? The first? OK, I select "string" as the first argument. Save and test. Panel is not visible.
Go back and try setting all three to 'string' . Nope, still doesn't work.
So two problems here, one I could not get this to work, and two it showed 3 dropdowns for argument although the view only needs one.
Comment #18
heivoll CreditAttribution: heivoll commentedI am getting the same problems as tripper54, except that when using it as a Visibility rule for a pane, i get two argument selectors, not three. Perhaps that could be because the View has two different arguments in total, but spread over different displays?
Comment #19
ndf CreditAttribution: ndf commentedHmm, I missed something obvious.
1. String context
The 'string' context is different that the other real objects like user, node, etc.
In the function _ctools_view_access_get_argument_from_contexts() that is checked now. Silly I did not test that properly.
This is totally separated from the input method via a panel-visibility- or selection-rule. It would happen to with direct input (i.e. %string). So I am a bit worried that there could be other unknown exceptions too.
2. Argument selectors
About the input method with the multiple selectors.
The thing what happens is that all available contexts will be presented here independent if the View can handle them. The reason is that we don't have a proper ajax-callback that loads the view when you selected it. But it sounds like a better, less confusing UI.
So at least you will see one context (that is "Logged in user") and if your are on the node-panel you will see 2 ("Node being viewed" & "Logged in user") that you can pass into the view. If you add a string-context, you'll see 3 argument selectors.
In addition to the patch file also added 'test_node_panel" that makes use of the "test_view".
So test setup:
panels 3.4 stable
ctools 7.x-1.x-dev
patched ctools_view_access
test_view.txt
test_node_panel.txt
Maybe this is getting a bit to difficult all the way, but I still hope we could manage to fix this feature.
Comment #20
tripper54 CreditAttribution: tripper54 commented@niels,
The string argument works now, thanks.
The problem with the number of argument selectors remains.
So if I understand correctly, the number of selectors I'm presented with will depend on the number of contexts available eg, if I have 'node' , 'user' and 'string' , I'll get three selectors, regardless of the number of arguments the view requires.
This is no good, I'm afraid. The number of selectors needs to correspond with the number of arguments from required by the view. Otherwise it's too confusing.
As I mentioned above, I did try to get this working via ajax callbacks, but these Ctools forms aren't rendered by the core form API, so core-style AJAX doesn't work.
Another option that seems like a common pattern is to make the form multi-step: in step one we select the view, then in step 2 we choose the arguments (if any).
Have you explored that?
Comment #21
ndf CreditAttribution: ndf commentedYes, clear. That means work to do. I'll dive into it: both ajax and multistep.
Nice change to learn something new!
Comment #22
ndf CreditAttribution: ndf commentedTried a long shot on the ajax, but at gave up. Got to many issues with ctools+ajax.
So what I did was using patch #5 and then I added functionality from the later patches:
I tested:
Both 'selection rules' as 'visibility rules'.
Log notices
If we want to give feedback to the user what arguments a view can handle, we might do that by extending the view-instance label with arguments. The view object contains this information. But this functionality is not in this patch though.
Comment #24
tripper54 CreditAttribution: tripper54 commentedCommitted! Thanks @nielsdefeyter for your work on this.
Comment #25
ndf CreditAttribution: ndf commentedThanks!