Unable to use path arguments because they ain't passed

R.Muilwijk - July 9, 2008 - 11:19
Project:Views
Version:6.x-2.0-rc1
Component:block displays
Category:feature request
Priority:normal
Assigned:Unassigned
Status:by design
Description

At the moment hook_block doesn't send any arguments to display_execute:

      if ($view = views_get_view($name)) {
        if ($view->access($display_id)) {
          $output = $view->execute_display($display_id);
          vpr("Block $view->name execute time: " . (microtime() - $start) * 1000 . "ms");
          $view->destroy();
          return $output;
        }
      }

But at the moment in the view itself there ain't added any arguments for block display. There for I was not able to use the path arguments and I had to make a work around:

function module_views_pre_view(&$view, &$display_id, &$args) {
  // Views currently doesn't support path arguments to be used blocks
  // We add our taxonomy argument here
  if ($view->name == 'myview' && $display_id == 'myblock') {
    $args = array(arg(1));
  }
}

Can't we add something like when you click on 'Arguments' that you are able to select wehre to get the arguments from?

#1

mooffie - July 9, 2008 - 12:33
Category:bug report» support request

Can't we add something like when you click on 'Arguments' that you are able to select wehre to get the arguments from?

The feature exists already.

Go to the argument's settings form.

Under 'Action to take if argument is not present' choose 'Provide default argument'.

Under the new 'Default argument type' choose 'PHP Code'. In the textarea type "return arg(1);"

(To make these settings apply only for the 'myblock' block, as in your code example, 'Override' the arguments.)

At the moment hook_block doesn't send any arguments to display_execute:

Note that this isn't a bug: a block isn't tied to a URL, it can appear on various pages, so there isn't where to take the arguments from.

(Please mark this issue 'fixed' if you got your answer.)

#2

merlinofchaos - July 9, 2008 - 15:18
Status:active» by design

Wow, you haven't read the documentation at all, have you?

#3

merlinofchaos - July 9, 2008 - 15:22

Here, let me quote relevant sections of the documentation so that when you get mad at me for being a dick, you will have only yourself to blame:

From the help page on 'Arguments':

Arguments are input. While they often come from the URL, they don't always so please don't be shocked when they don't. Each display time may have its own source for arguments. Block displays have no source of arguments at all; they cannot pull arguments from the URL, and often require use of the PHP code default in order to get arguments.

From the help page on 'Block displays':

Blocks do not accept arguments from any source; the only way to get arguments to a block is to provide defaults to it, possibly via the PHP Code default setting.

Let me say this again: BLOCK DISPLAYS CANNOT ACCEPT ARGUMENTS FROM THE URL. Blocks DO NOT KNOW what the actual URL was, they CANNOT accept 'path arguments'. If you want to pull arguments from the URL, you use PHP code and the arg() functions to pull the pieces of the URL you need, but since they DO NOT KNOW WHAT THE URL IS they cannot know WHAT THE PATH ARGUMENTS ARE.

Please, read the damn documentation before posting issues.

#4

R.Muilwijk - July 9, 2008 - 17:24
Category:support request» feature request

I understand your frustration and it's my bad I haven't read the documentation well. The documentation I did read partially is the one followed from the project page:
http://drupal.org/handbook/modules/views

and

http://drupal.org/node/109604

I can tell you I just looked at it and still aren't able to find it so I guess it's in the help at the actual Drupal install and not , or not easy to find, at the documentation linked from the project page.

I still think it would be a nice feature to be able to use the path arguments for a block display in the interface. I guess it would be a feature request then and that it currently ain't like that by design.

#5

merlinofchaos - July 9, 2008 - 18:05

I still think it would be a nice feature to be able to use the path arguments for a block display in the interface. I guess it would be a feature request then and that it currently ain't like that by design.

I'm sorry, what part of "can't know" did not make sense? It's not possible. Blocks do not know what the base path is, they do not have access to the arguments.

#6

merlinofchaos - July 9, 2008 - 18:07

Also, if you installed the advanced help module, there's a help icon right next to the description of the block display that brings up the help in question. Views pretty much demands you install the advanced help module. If you did not install it, I forbid you from entering new issues until you do.

#7

MikeSchinkel - July 25, 2008 - 00:42

WOW, looks like batsonjay was spot-on about the Drupal forums:

http://acquia.com/blog/making-drupal-better-a-daily-task

#8

MikeSchinkel - July 25, 2008 - 00:52

With solutions like you described, it is no wonder what Drupal is getting hammered by Joomla and WordPress. I've starting to tag a running list tweets where people are choosing Joomla and WordPress over Drupal. I've seen over ten in the past few days, but this post has me motivated to maintain the list in earnest in hopes to get the community to recognize that it is an issue:

http://del.icio.us/MikeSchinkel/drupal+fail

Sure would be nice if the community felt it was important to make common use-cases obvious and easy rather than attack those who are confused and feel vindicated when something only obscure and arcane (to most people) addresses the issue.

JMTCW.

#9

merlinofchaos - July 25, 2008 - 16:36

Mike: Don't care. This is an issue queue where I deal with issues with the Views module. This is not an appropriate place to post your stuff. There are many other places that you can post this stuff freely. Please do not post it here.

#10

merlinofchaos - July 25, 2008 - 16:41

BTW, Mike, since you brought it up here, if you want to actually help fix the problem, please spend about 8 hours a day in the Views queue offering friendly, helpful customer support. But complaining about my taciturn and dour manner is annoying at best and hypocritical at worst. I provide one hell of a piece of software, for free, and I do bucketloads of work to try and provide a good UI. And I don't care if you don't appreciate that work, but I do care that the primary reward I get for doing work is...to be yelled at for not providing this free service with a smile and a thank you when someone can't read the documentation. I love the expectation that 1 guy should be able to support a quarter million users and make them all happy.

Also, for what it's worth, I spoke with the author of the post on IRC and he was not at all bothered by my response (and he did figure out his issues).

 
 

Drupal is a registered trademark of Dries Buytaert.