"First name only" not appearing in Views output

frankcarey - December 26, 2007 - 20:20
Project:Fullname field for CCK
Version:5.x-1.5
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:needs review
Description

When creating a view, and selecting options:

"Last name only" works fine, but "First name only" does not.

There was an error in the code near line 749 where

$cck_fullname['first_preferred'] was set, but ['first'] is used in the output so no first name ever shows up.

Also, isset() was used where !empty() would probably be more appropriate. It looks like ['first_preferred'] keys are set, even if they are blank.

The fix is below... not sure how to submit patch.

Existing code

<?php
  
case 'last_name_only'://output legal last name
      //check and clean the values for output
       
if (isset($item['last'])) {
         
$cck_fullname['last'] = strip_tags($item['last']);
        }
       
$output .= theme('cck_fullname', $cck_fullname, $field);
      return
$output;
    case
'first_name_only'://output preferred first name
      //check and clean the values for output
       
if (isset($item['first_preferred'])) {
         
$cck_fullname['first_preferred'] = strip_tags($item['first_preferred']);
        }
       
$output .= theme('cck_fullname', $cck_fullname, $field);
      return
$output;
?>

Fixed Code

<?php
  
case 'last_name_only'://output legal last name
      //check and clean the values for output
       
if (!empty($item['last'])) {
         
$cck_fullname['last'] = strip_tags($item['last']);
        }
       
$output .= theme('cck_fullname', $cck_fullname, $field);
      return
$output;
    case
'first_name_only'://output preferred first name
      //check and clean the values for output
       
       
if(!empty($item['first'])) {
         
$cck_fullname['first'] = strip_tags($item['first']);
        }
        if (!empty(
$item['first_preferred'])) {
         
$cck_fullname['first'] = strip_tags($item['first_preferred']);
        }
       
$output .= theme('cck_fullname', $cck_fullname, $field);
      return
$output;
?>

#1

rconstantine - December 27, 2007 - 20:55

Firstly, FYI Drupal etiquette is that a poster doesn't mark his/her own patch as "ready to be committed" since a lot of factors could mean that it isn't. Fortunately in this case, you identified the fact that the preferred first name should take precedence over the legal name for display purposes (although a legal first option could be added), and you correctly overwrite it if it is set.

So yes, this looks ready to be committed. Thanks for the code. [I haven't used all of these features myself, so I appreciate it when someone who needs them is able to correct them.]

I'm still open to any other help that would make this module work better with Views if you know how to do it.

Will try to get another release out soon...?

#2

frankcarey - January 2, 2008 - 01:50

my bad... (my first patch).. thanks for the heads up.

#3

Petra - January 19, 2008 - 16:05

Fortunately in this case, you identified the fact that the preferred first name should take precedence over the legal name for display purposes (although a legal first option could be added), and you correctly overwrite it if it is set.

This is inconsistent for me. Preferred name has the same fields als legal name. So why take preferred first, when it's called first name.
Please add a legal first option.

I tried the code - it works, but in a talbe view the column for "First name only" will be sorted in order of "Last name only". "Last name only" sorts the names correct. Any idea how to fix this?

#4

webmasterkai - March 4, 2008 - 00:03

Patch works for me.

AttachmentSize
cck_fullname.diff 1.36 KB

#5

nasi - February 25, 2009 - 18:50
Status:reviewed & tested by the community» needs review

I've just found this issue having come across the same problem and written my own fix!

My patch is very similar to the one already submitted, in that I made the same assumption that a preferred name (if present) should be shown in preference to a legal name. However, I also applied that same logic to the display of the last name and my code logic doesn't perform redundant operations if both names are present.

As for the sorting, I think that would require deeper integration with Views - at least to add further options to the fullname sort criteria.

AttachmentSize
cck_fullname_p2.diff 1.44 KB
 
 

Drupal is a registered trademark of Dries Buytaert.