Closed (fixed)
Project:
Views (for Drupal 7)
Version:
6.x-2.6
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
27 Oct 2009 at 23:11 UTC
Updated:
11 Dec 2009 at 18:10 UTC
When using the php code validation for arguments, the validation is always false.
I confirmed it was not running the validation code at all, as drupal_set_message() does nothing.
My code was something like this:
drupal_set_message('argument: ' . $argument);
$node = node_load('title' => $argument);
drupal_set_message('title: ' . $node->title);
if(empty($node))
return FALSE;
return TRUE;
I left out the php tags per instruction.
Comments
Comment #1
dawehnerAfaik the php validation is not runned, if you pass no argument. It this the case?
Comment #2
RoboPhred commentedI think that's true, but I am passing an argument. The point of my validation code was to make sure a valid node was passed by title.
The argument is a Node: Title type with a relationship to a cck nodereference field.
Comment #3
sja1 commentedI am having this same problem, here are the details.
I am displaying a views block on a panels 3 page panel. The view has 1 argument, a node reference cck field. Rather than receive the argument from panels, I want to programmatically set the argument from within the view by writing default argument php code. To do this, in my panel definition I set the view's pane option to "No context" in the hope that by doing so no arguments will get passed to the view, thereby triggering the default argument code. Within the view, the "Action to take if argument is not present: " is set to "provide default argument", and "default argument type" is set to php.
I tested this, and saw that the default argument php code was not being run. By putting php code in the view header to print out the view definition, I saw that an "argument" was indeed being sent by panels. Panels was returning as argument an array with 1 value whose key is the name of the field containing the node reference nid, and whose value is an object called "content_handler_argument_reference", and which when expanded shows a value of "recursion".
Assuming that this value in "argument" was causing my default argument code not to run, I then decided to try setting the argument from within the validation code. There is a note beneath the "php validate code" box that says "You may change the argument by setting "$handler->argument". So in the view I set "Action to take if argument is not present:" back to "display empty text", and put code to alter $handler-> argument in the "php validate code" box. Nevertheless, that that code wouldn't run either.
However, I found that if I set "Provide default argument" to php, then BOTH the default argument code AND the validation code get run. If only one or the other is set, then neither is run.
This seems likely to me to be a bug.
Comment #4
merlinofchaos commentedWhat options do you have selected for that pane in Panels?
Comment #5
izmeez commentedI just came across this issue and I have been struggling with the views argument validation using PHP code and thought it was my own lack of understanding.
In http://drupal.org/node/631236 I have described my attempt to use php code to validate if a group is of a specific type. Any help would be appreciated.
I was also wondering about putting in a feature request to select Group nodes with selection of specific group types, but wanted to try to get it working using the php code validation.
Thanks,
Izzy
Comment #6
sja1 commentedHi, the only option that has a value is the context for "Content: Belongs To (field_belongs_to):" and its set to "no context." field_belongs_to is a nodereference.
However, I think my problem might have been caused in part (if not entirely) because the php code I was trying to run executes a view, similar to the following:
I was able to create the argument properly, but the next problem was that somehow the argument was passed back into the wrong view. The sequence was like this:
1) View 1 starts execution
2) Within view 1, custom default argument code executes view 2 to construct an argument for view 1
3) Instead of view 1, View 3 (!!) gets rendered using the argument constructed in step 2
I imagine the module wasn't designed for the possibility of executing a view within the argument handling code. I resolved the problem by getting rid of the views calls, and writing an sql statement and using db_query to get the node ids I need. I have this code as "php validate code", and in the "php argument code" I put the following, mainly because I'm not sure how panels and views interactions affect the execution or not of the validation code:
It all works now, but if there is an easier way of achieving this I'd be glad to know it. The first solution I investigated was to see if Panels allows you to define an argument using php to be passed to the view, but that option doesn't seem to exist, so I settled on setting the argument within the view itself.
Comment #7
kenorb commentedI've got 'return TRUE;' (PHP validate code) and rows disappears, validation function is called. Probably it's related.
Comment #8
merlinofchaos commentedsja1: I suspect that your $view = ... was overwriting the $view you were already in.
If I interpret this right, we've got things working here and this can be marked fixed?