i have created a view with a block display. this view accepts an argument which is 'date: date content' which is tied to a cck date field. this block is displayed for a path of "news/*" which includes views and path aliased nodes. i've set the granularity to year.
the paths are set up to be 'news/2009' (for the page view which returns all values for 2009 on this case) or 'news/2009/title_of_node' (for individual nodes). in both cases i have the second part of the url used as the argument in the block view. to accomplish this i am using the following php default argument:
if ((arg(0) == 'news') && is_numeric(arg(1))) {
return arg(1);
}
if ((arg(0) == 'node') && is_numeric(arg(1))) {
$path = explode('/', drupal_get_path_alias($_GET['q']));
return $path['1'];
}
on pages that are views, everything works fine. however, on pages that are nodes the argument is never passed to the block view.
i've done several things to test for what the problem is.
- i have included on my page template the node argument code and printed the result which is the correct date argument.
- i have provided a static default argument.
- i have tried using the node created date as the argument
all of these display the block's empty values only when viewing a node, but work otherwise.
has anyone else experienced this issue? what can i do to correct the problem?
thanks for your help in advance.
Comments
Comment #1
nevets commentedOne thing I see is
return $path['1'];should probably bereturn $path[1];Comment #2
masande commentedi've changed the array key, cleared the views / site cache and no change. the year is still not passed as an argument when viewing a node.
Comment #3
nevets commentedAfter
try adding
to set what $path looks like when visiting a node.
Comment #4
masande commentedhere's what i get:
actually, i wasn't sure if you wanted to add the code to the argument handling code or not. i added it to the top of my page template, instead. if i added your code to the argument handling php nothing was returned.
could this be the problem?
Comment #5
nevets commentedYou are now on the right track since you do not see it when added to the argument handler. So lets change the argument handling code
to
You should see a pair of messages.
Comment #6
masande commentedok, i only see the messages for arg(1) and not when viewing a node. what gives?
Comment #7
nevets commentedIt's behaving like you have block visibility settings for path.
Comment #8
masande commentedthat's what i thought, too. so i have the block being shown on every page.
to prove that it is working, i set the block view to show all values if the argument is not passed. and sure enough that's what it does when viewing nodes.
which brings me back to my original question, why is the argument not being passed (or processed) when viewing a node?
Comment #9
nevets commentedDoes it even print ""Default Argument Handling - Entry"? (the first unconditional message)?
Comment #10
masande commentednope. completely blank. i've double checked the block visibility and i have no restrictions.
as a test i tried pulling in the nid from the url as an argument with the messages you suggested. this worked when viewing a node. that's why i sort of suspect a problem with the date module argument handling code and viewing nodes.
Comment #11
masande commentedi'm beginning to think there is a problem with assigning default arguments when viewing nodes. when setting 'Provide default argument', i've tried a variety of options related to passing the year as an argument. 'php code' will not pass the argument in any way when viewing a node. 'current node's creation time' or 'current node's update time' will not pass an argument either when view a node. even 'fixed entry' does not work.
however, 'current date' does correctly provide the argument.
i wish i knew more about the views api so i could do a more exhaustive debug or even track down possible sources of the problem, but i am completely overwhelmed by it.
Comment #12
masande commentedso i tested this problem on a different drupal installation and had the same issue, default date arguments are not being passed to blocks when viewing a node.
i'm trying to create a list of all the nodes with a user set date corresponding to the year of the currently viewed node. without this ability, my site is dead in the water.
can anyone else try to replicate this problem? i find it hard to believe i'm the only one with the problem so i suspect it's a config issue or similar.
all my attempts at passing an argument to the block (when viewing a node) display the does not validate action.
Comment #13
masande commentedwell, the latest update to the date module has produced some changes. the date arguments that are listed are now clearly distinguished between 'date: date (node)' and 'date: date (user)'. checking my views after update showed that i had indeed set the arguments to 'date: date (user)' which is incorrect.
i've updated all my views to 'date: date (node)' and was enthusiastically hoping this would correct the issue, but it did not.
no matter what i do i can not get a default date argument to be passed to a block display when viewing a node.
Comment #14
drauta@drauta.com commentedI have the same problem, is there any solution?
I'm using a block view to show events for one day. That day is sent by URL in "Y-m-d" format. My block view appears in a node page and it looks like it isn't receiving any argument.
I've tried that same block in other pages (not-node ones), like front page, and it works fine.
Comment #15
masande commentedi'm happy that i'm not the only one who has experienced this problem.
as a work-around, i created a custom block and used views_embed_view() to display the view. for my example from above following is the code i used with my view name 'news_month'.
Comment #16
karens commentedI have no clue at all what this is talking about. I need at the very least an export of the view to see what in the heck you are talking about. Blocks don't receive arguments normally so I'm totally in the dark about whether this is some confusion about how views works or something specific to the date module.
Comment #17
masande commentedof course views that are output as a block can except arguments, but not from the url. they are provided via php default argument handling. do it all the time and have several on this site that work correctly.
as for the view export, see below.
Comment #18
restlesscoder commentedI just encountered a very similar problem on one of my Drupal sites, except the argument was a normal string field, not a date. The default argument PHP code did not seem to be executing at all with the view as a block. I disabled the Content Permissions module in CCK, and the problem went away. Could this date field bug be an issue with Content Permissions as well?
Comment #19
smoothify commentedI ran into something similar to this today, I believe the issue is in the views module.
I have created an issue and patch here:
#657384: Default date arguments set incorrectly when path contains node/%
Comment #20
smoothify commentedComment #21
arlinsandbulte commentedDoes #657384 solve this issue now that it is in?
Comment #22
arlinsandbulte commentedNo reply.
Assume fixed.