0

I'm using the Views module and Drupal 7 and want to add a class to all rows of my table that have a certain value for a certain field.

The field is a bit field and is included in my query. I have added a PHP field (a separate Views module that is installed) with the following code:

if ($row->field_kampioen || $row->field_spirit) {
    return 'views-table-highlight';
} else {
    return '';
}

This should allow me to set the row class to [php]. This works, but all rows get the css class. When I output this for debugging:

return $row->field_champion . ' ' . $row->field_spirit . ' ';

I see that the classes are all different numbers, and field_champion is equal to field_spirit. This makes me think I'm seeing the ID.

How can I get a TRUE of FALSE? So, how can I get the actual bit value of this field?

It would be nice if I could do this via the Views module only, but I've seen pages where hooks are used. Maybe I'll have to use that.

  • are you using drupal 6 or 7? – Bala Feb 25 '14 at 12:25
  • Sorry. Drupal 7. I updated my question. – Peter Feb 25 '14 at 12:49
0

I'm assuming you are using Drupal 6, since you mentioned about PHP filed.

below is the code to retrieve value from a field and where ['tid_1'] is the token for a field. I think this is similar for Drupal 7 too.

<?php     
$static = $this->view->display_handler->get_handlers('field');    

$b=$static['tid_1']->last_render; //$b contains the value of the field
$d=$static['tid_2']->last_render; //$d contains the value of the field   
//use your logic
 ?>
  • Is it possible this method (last_render) no longer exists? I know I have an object of type views_handler_field_field because I tried using it as an array and got a error stating I couldn't use this type as an array. But last_render doesn't give me anything. Other methods I found give me nothing or the wrong value (for example get_field gives me the name of the field, i.e. 'field-spirit-value'). – Peter Feb 25 '14 at 14:15
  • @Peter i will check this in d7 tommrow. – Bala Feb 25 '14 at 15:20

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.