Hi!

So this is a relatively specific bug. I think the title says it all. "Custom Views Access Plugin will not replace integer with argument if view is a default tab creating a new parent menu tab".

Switch to a default tab with an existing menu item, no problem.
Switch to a current tab with an existing menu item, no problem.
But, switch to a default tab where it creates a prent item, and it passes "0" or "1" instead of "node" and "nid".

Thanks for looking at this! The argument replacement function of views access plugins are very handy.

CommentFileSizeAuthor
#2 myaccessfunction_plugin_access.txt1.63 KBnagiek
#2 view.txt10.16 KBnagiek
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

Status: Active » Postponed (maintainer needs more info)

Even you don't believe it it is always handy if you provide a view export which is really easy to reproduce :)

nagiek’s picture

Status: Postponed (maintainer needs more info) » Active
FileSize
10.16 KB
1.63 KB

Sorry I have a bad habit of that... :)

There's a custom function in the access callback, but you can just set it to anything to check the arg that's being pushed through.

nagiek’s picture

Status: Needs review » Active

So here's what I believe is the problem. No patch because my computer is in the shop... :p

Here is the code in views_plugin_display_page.inc that replaces integers with dynamic arguments:

    // Get access callback might return an array of the callback + the dynamic arguments.
    $access_plugin_callback = $access_plugin->get_access_callback();

    if (is_array($access_plugin_callback)) {
      $access_arguments = array();

      // Find the plugin arguments.
      $access_plugin_method = array_shift($access_plugin_callback);
      $access_plugin_arguments = array_shift($access_plugin_callback);
      if (!is_array($access_plugin_arguments)) {
        $access_plugin_arguments = array();
      }

      $access_arguments[0] = array($access_plugin_method, &$access_plugin_arguments);

      // Move the plugin arguments to the access arguments array.
      $i = 1;
      foreach ($access_plugin_arguments as $key => $value) {
        if (is_int($value)) {
          $access_arguments[$i] = $value;
          $access_plugin_arguments[$key] = $i;
          $i++;
        }
      }
    }
    else {
      $access_arguments = array($access_plugin_callback);
    }

$access_arguments is then registered for later.

    if ($path) {
      $items[$path] = array(
        // default views page entry
        'page callback' => 'views_page',
        'page arguments' => $page_arguments,
        // Default access check (per display)
        'access callback' => 'views_access',
  --> 'access arguments' => $access_arguments,   <--

BUT, when creating a new menu tab, we don't pass in the $access_arguments.

      if ($menu['type'] == 'default tab') {
        $tab_options = $this->get_option('tab_options');
        if (!empty($tab_options['type']) && $tab_options['type'] != 'none') {
          $bits = explode('/', $path);
          // Remove the last piece.
          $bit = array_pop($bits);

          // we can't do this if they tried to make the last path bit variable.
          // @todo: We can validate this.
          if ($bit != '%views_arg' && !empty($bits)) {
            $default_path = implode('/', $bits);
            $items[$default_path] = array(
              // default views page entry
              'page callback' => 'views_page',
              'page arguments' => $page_arguments,
              // Default access check (per display)
              'access callback' => 'views_access',
      -->   'access arguments' => array($access_plugin->get_access_callback()),  <--

If we pass in $access_arguments, my problem should be fixed :) and views will be so much the better.

Again, sorry no patch. Thanks dereine!

nagiek’s picture

Status: Active » Needs review
dawehner’s picture

Status: Active » Needs review

Oh it's so much easier to understand what you change if you create a patch file.

nagiek’s picture

Just last line.

-   'access arguments' => array($access_plugin->get_access_callback()),
+   'access arguments' => $access_arguments,

Will post patch when I get my computer back (should be today)!

dawehner’s picture

Status: Needs review » Fixed

It's all about context :) Anyway i found the line so changed it and commited to both 3.x branch.

Thanks for providing a "patch"...

nagiek’s picture

Thanks. :) Sorry I wasn't more help.

Status: Fixed » Closed (fixed)

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