[Solved] Views 2: Handling Arguments Titles
Hi
I am confused on how to present a Title that is representative of a prepared Path; whereby the value used within Path's % args will not be the presented value used by the Title.
For example, let's say I have a content type Project that is represented by Project ID 65 and a Project Name "Build Bridge". Every Project has a set of Tasks, and each Task maintains its relation to a Project with a database field task_project_id.
I have got the basics down on how to use Views' arguments:
- I define an argument for %1 argument to refer to task_project_id, which has a views_handler_argument_numeric defined within Task's hook_views_data().
- I define a path /project/%/tasks.
- This works great in finding all the tasks for a project based upon filtering upon task_project_id
Now I want to set up the Argument Title. Instead of using the Project ID within this Title, referred to by %1, I want to use Project Name to represent the path Project ID. It is not clear to me how to do this.
I thought may be "Argument Handling code" would help, http://drupal.org/node/70145, but it does appear to exist in Views 2.
How can this be done?
Thanks
Jeff in Seattle


Solved using views_get_current_view()
I found a work-around using Drupal functions
views_get_current_view()anddrupal_set_title().Inserting the following PHP code within Header set for "Input Format: PHP Code:
<?php
$view = views_get_current_view();
$args = $view->args;
$task_project_id = $args[0]; // %1
$project_name = __custom_function_get_project_name(task_project_id
$title = 'Tasks of Project "'. $project_name.'"';
drupal_set_title($title);
?>
...or implement
...or implement title_query() in your handler...
taken from views_handler_argument_node_nid.inc
<?php
/**
* Override the behavior of title(). Get the title of the node.
*/
function title_query() {
$titles = array();
$placeholders = implode(', ', array_fill(0, sizeof($this->value), '%d'));
$result = db_query("SELECT n.title FROM {node} n WHERE n.nid IN ($placeholders)", $this->value);
while ($term = db_fetch_object($result)) {
$titles[] = check_plain($term->title);
}
return $titles;
}
?>