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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

merlinofchaos’s picture

This functionality is part of the 3.x roadmap (see http://www.angrydonuts.com/views-3-x-roadmap) so patches will be very appreciated here!

dagmar’s picture

Issue tags: +views 3.x roadmap

Tagging.

Cyberwolf’s picture

FileSize
2.54 KB

Attaching a patch against HEAD. Let me know what you think about it.

dagmar’s picture

I didn't test it but, the syntax of $variables in views is $variable_one and not $variableOne

Cyberwolf’s picture

Sorry, I'm used to camel case coding style :) Will fix it when I have some more time.

dawehner’s picture

Status: Active » Needs work

.

dawehner’s picture

FileSize
2.22 KB

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

dawehner’s picture

Status: Needs work » Needs review
FileSize
2.47 KB

This is the same patch which some comment inline. I would suggest to review this part, i don't know whether i understood it right.

dawehner’s picture

Status: Needs review » Needs work
+++ plugins/views_plugin_display_page.inc
@@ -71,6 +71,36 @@ class views_plugin_display_page extends views_plugin_display {
+        if (is_int($value)) {
+          $access_arguments[$i] = $value;
+          $access_plugin_arguments[$key] = $i;
+          $i++;
+        }

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

+++ views.module
@@ -453,6 +453,12 @@ function views_access() {
+      if (is_int($value) && isset($args[$value])) {
+        $arguments[$key] = $args[$value];
+      }

The same case here.

Powered by Dreditor.

dawehner’s picture

Status: Needs work » Needs review

The access plugin can do this already.

dawehner’s picture

Issue tags: +alpha-4 blocker

add tag

Remon’s picture

Bumping last alpha-4 blocker.

merlinofchaos’s picture

Priority: Normal » Critical
Status: Needs review » Needs work

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

merlinofchaos’s picture

Assigned: Unassigned » merlinofchaos

Assigning to myself. This isn't because I'm working on it, but because I want faster notification of rerolls.

dawehner’s picture

Status: Needs work » Needs review
FileSize
2.51 KB

Okay 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"?

dawehner’s picture

Here is a patch with full testing.

Simpletests are quite frustrating to write. You get many problems with static caching etc.

merlinofchaos’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev
Status: Needs review » Patch (to be ported)

Committed to 3.x; not going to try on 7.x, I suspect at the very least the tests need updating.

dawehner’s picture

Version: 7.x-3.x-dev » 6.x-3.x-dev
Status: Patch (to be ported) » Fixed

Commited to the 7.x branch. Thanks to everyone who worked on this issue.

dawehner’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev

ups

Status: Fixed » Closed (fixed)
Issue tags: -views 3.x roadmap, -alpha-4 blocker

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