When using nodereference or userreference arguments in a view's title, the title contains the node ID or user ID instead of the node title or user name. The behavior should be the same as when the node ID or user ID are used as arguments:
http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/views/modul...
http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/views/modul...

CommentFileSizeAuthor
#1 cck-397358-1_DRUPAL-6--2.patch4.55 KBdarren oh

Comments

darren oh’s picture

Status: Active » Needs review
StatusFileSize
new4.55 KB

Patch works for me on nodereference arguments.

yched’s picture

Status: Needs review » Fixed

Committed to 6.x-2.x-dev, slightly modified ($this->view->base_table and $this->view->base_field don't work when using a userref field on a View listing nodes)
Thanks !

markus_petrux’s picture

Status: Fixed » Active

Sorry to bump this, but it seems to me there's a bug. Sorry if I'm wrong. I just looked at the code.

Snippet in method title_query() of the new class content_handler_argument_reference:

    $result = db_query("SELECT $this->name_field FROM {{$this->view->base_table}} WHERE {$this->view->base_field} IN ($placeholders)", $this->value);
    while ($term = db_fetch_object($result)) {
      $titles[] = check_plain($term->title);
    }

Note that the field name in the query is built from the contents of a property of $this, but we're taking $term->title in the while loop. I think "title" is correct field name for nodes, but not for users, which should be "name".

So maybe that piece could use a field alias in the query.

    $result = db_query("SELECT $this->name_field AS title FROM {{$this->view->base_table}} WHERE {$this->view->base_field} IN ($placeholders)", $this->value);
    while ($term = db_fetch_object($result)) {
      $titles[] = check_plain($term->title);
    }

Now, $term->title is aliased to "title", so it works for nodes and users.

yched’s picture

Status: Active » Fixed

Oops, indeed. Fixed, thanks Markus.

Status: Fixed » Closed (fixed)

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