Hi,

I've a node with a user reference cck field.
That cck field is configured to query a view to display a list of users in a dropdown list.

The view is a user list with just two fields name forename and familyname (both profile fields). Previewing the views should a list of forename / familynames correctly.

However, when one adds a new node, the user reference drop down list contains:
FamilyName - Forename - Name: USERNAME
I'd like to remove the dashes, and the last part "Name: username".

After searching the issue Q for a while, I added "uid" as a hidden field to the view, but that made no difference.

Also: I tried overriding the display of a field with views-view-field--VIEWNAME--default--value.tpl.php, but this too is ignored in the user reference dropdown list.

How does one format the fields in the user reference selection list, and remove the trailing user name?

Thanks in advance..

Comments

mtbradle’s picture

subscribing

dawehner’s picture

Project: Views (for Drupal 7) » Content Construction Kit (CCK)
Version: 6.x-2.11 » 6.x-2.x-dev
Component: user data » Views Integration

I guess this is a userreference problem. I cannot think of anything which changed here.

boran’s picture

Dereine: so you have seen this issue too?

dawehner’s picture

No, i just hanged around in the issue queue.

petermilad’s picture

subscribing

schultetwin’s picture

I believe the code that is causing this is in the userreference.module at line 742. The userreference module must have the user name in order to validate the field.

    // We do need name field, so add it if not present (unlikely, but...)
    $fields = $view->get_items('field', $display);
    if (!isset($fields['name'])) {
      $view->add_item($display, 'field', 'users', 'name');
    }

Anyway, I've fixed the issue by adding the user name as a display field to my view and then just excluding it from the view. That works fine, although a bit hackish.

boran’s picture

Status: Active » Patch (to be ported)

That explains things, and adding the user to the view works as suggested.

I'll change the status to "patch", since the fix works, but the maintainers might like to consider your change.

sdragnev’s picture

boran: Did you manage to get rid of the dashes and if so how?

UPDATE: Nevermind, figured it out. Couldn't use a table style in the view.
Switching to unformatted and then using Row Style to set the separator did the job.

lendude’s picture

Version: 6.x-2.x-dev » 6.x-2.9
StatusFileSize
new711 bytes

I ran into the same problem. I found the same work-around as schultetwin, but it indeed feels hackish and a tiny bit counterintuitive (add 'name' to your view to remove it from the display...)

I wrote a patch that should fix the issue. The 'name' field is still added but by sending the option 'exclude' it is not displayed (so pretty much what the workaround did, except programmatically). This feels right, since whoever made the view didn't want to show the name in the first place (or they would have added it themselves).

I changed the line
$view->add_item($display, 'field', 'users', 'name');
to:
$view->add_item($display, 'field', 'users', 'name', array('exclude' => 1));

I made the patch from 2.9 but the same issue is in 3.x

Len

aaustin’s picture

Agreed, works but I never would have figured it out without Google and this issue queue.

Anyway, I've fixed the issue by adding the user name as a display field to my view and then just excluding it from the view. That works fine, although a bit hackish.

kscheirer’s picture

Status: Patch (to be ported) » Needs review

Just ran into this too. It is indeed weird, but the "add user: name field, and then exclude from display" trick works. Setting to "needs review" since a patch is posted and looks reasonable.