2

I am using a global php field in drupal views to display a list of names. If the contact record has extra info in a custom note (rich text editor) field, I want to display "name, info". If there is no extra info, I just want to display "name". This is what I am using as the output code of the global php field:

<?php
if (!empty($row->id_info_for_display_33)) {
    print $row->display_name . ", " . $row->id_info_for_display_33;
}
else {
    print $row->display_name;
}
?>

It seems that the custom field is never really empty unless it is a record that was created before the custom field was added. Even then, if I then edit that record, the custom field is no longer empty and the display ends up as "name,".

Any ideas on what logic will accomplish this?

Civi 4.6.2

Drupal 7.38

Views 7-3.11

Thanks!

3

Looks like the CiviCRM is adding a space '&nbsp;' (may be because of CKEditor) into the custom table column , even though you leave it empty when adding/editing the record.

You can see it if you do var_dump of the variable. See below screenshot

enter image description here

So the below logic should work in this case.

<?php
if ($row->id_info_for_display_33 !== '&nbsp;'  && !empty($row->id_info_for_display_33)) {
    print $row->display_name . ", " . $row->id_info_for_display_33;
}
else {
    print $row->display_name;
}
?>

Give it a try.

  • Thanks... This def helped me out. For me, the wysiwyg was adding 2 spaces so this is what worked: <?php if ($row->id_info_for_display_33 !== ' ' && !empty($row->id_info_for_display_33)) { print $row->display_name . ", " . $row->id_info_for_display_33; } else { print $row->display_name; } ?> – Daniel Strum Jun 30 '15 at 3:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.