I am trying to accomplish the following:
I have made a view with a "page" display, that uses one argument to filter by taxonomy term ID. By using the taxonomy_menu module I create a menu of the taxonomy terms of which each menu item points to the view. Now I would like to hide (deny access) all menu items that point to a term to which there are no nodes associated.
I've tried writing a Views access plugin to accomplish this. However, I'm getting into trouble when trying to get grip on dynamic access arguments. It seems not to be possible to pass them to my views access plugin.
function get_access_callback() {
return array('option_views_check_terms_having_nodes', array(1));
}
menu_unserialize() does dynamic argument replacements in the array inside access_arguments, but in the case of views the actual access arguments for the access plugin are located in a nested array inside the main array.
example access_arguments:
array(1) {
[0]=>
array(2) {
[0]=>
string(46) "option_views_check_terms_having_nodes"
[1]=>
array(1) {
[0]=>
int(1)
}
}
}
What I suggest to fix this is that any integer access arguments returned by get_access_callback() of a views access plugin are added to the main access_arguments() array, so they get replaced there dynamically with the path argument by menu_unserialize():
array(1) {
[0]=>
array(2) {
[0]=>
string(46) "option_views_check_terms_having_nodes"
[1]=>
array(1) {
[0]=>
int(1) // 1 refers now to the key in the main array
}
},
[1]=>
}
Then, views_access() needs to replace the key pointers inside the nested arrays with the values from the main array.
I'm sorry if my explanation is not very clear :) I will try to write a patch.
Comment | File | Size | Author |
---|---|---|---|
#16 | 644008-views-dynamic_acesss_arguments.patch | 12 KB | dawehner |
#15 | 644008-views-dynamic_acesss_arguments.patch | 2.51 KB | dawehner |
#8 | 644008-views-dynamic_acesss_arguments.patch | 2.47 KB | dawehner |
#7 | views-644008.patch | 2.22 KB | dawehner |
#3 | views-644008.patch | 2.54 KB | Cyberwolf |
Comments
Comment #1
merlinofchaos CreditAttribution: merlinofchaos commentedThis functionality is part of the 3.x roadmap (see http://www.angrydonuts.com/views-3-x-roadmap) so patches will be very appreciated here!
Comment #2
dagmarTagging.
Comment #3
Cyberwolf CreditAttribution: Cyberwolf commentedAttaching a patch against HEAD. Let me know what you think about it.
Comment #4
dagmarI didn't test it but, the syntax of $variables in views is $variable_one and not $variableOne
Comment #5
Cyberwolf CreditAttribution: Cyberwolf commentedSorry, I'm used to camel case coding style :) Will fix it when I have some more time.
Comment #6
dawehner.
Comment #7
dawehnerUpdate codestyle, merge with current version, but
I would like to see a explanation whats going on in ivews_plugin_display_page, some inline comments would be important.
I don't really know whats happens here ;)
"Optional": A simpletest to test this would be cool.
Comment #8
dawehnerThis is the same patch which some comment inline. I would suggest to review this part, i don't know whether i understood it right.
Comment #9
dawehnerWe should allow to use strings too. Perhaps there is something which can be defined in the access plugin formular which whould be able for the access callback.
The same case here.
Powered by Dreditor.
Comment #10
dawehnerThe access plugin can do this already.
Comment #11
dawehneradd tag
Comment #12
Remon CreditAttribution: Remon commentedBumping last alpha-4 blocker.
Comment #13
merlinofchaos CreditAttribution: merlinofchaos commentedOkay. Patch doesn't apply, though hopefully it should be an easy reroll.
This also needs some documentation. I guess access plugins aren't really documented...at all, so maybe we should put in some stub documentation for access plugins somewhere to make it a little easier to understand how to do these.
Sadly, our access plugins are not nearly as interesting as CTools' access plugins, but maybe we can do some kind of transfer thing somewhere. That'd be pretty rad, though I don't have any idea how to actually get the complicated UI to fit inside the Views UI. Still, if we could do that, the amount of power we could gain would be extensive.
Comment #14
merlinofchaos CreditAttribution: merlinofchaos commentedAssigning to myself. This isn't because I'm working on it, but because I want faster notification of rerolls.
Comment #15
dawehnerOkay here is a fast rerole.
I'm not sure whether advanced help is the right place to write such specfic documentation for access plugins.
Wouldn't it be better to introduce a "views_plugin_example"?
Comment #16
dawehnerHere is a patch with full testing.
Simpletests are quite frustrating to write. You get many problems with static caching etc.
Comment #17
merlinofchaos CreditAttribution: merlinofchaos commentedCommitted to 3.x; not going to try on 7.x, I suspect at the very least the tests need updating.
Comment #18
dawehnerCommited to the 7.x branch. Thanks to everyone who worked on this issue.
Comment #19
dawehnerups