0

In my computed field I'm trying to make it display the field and it's label only if the value is negative. If it is above 0 it should not display anything, not even field label.

So far in "Display Code (PHP)" I have:

if $entity_field_item['value'] < '0' { ;
$display_output = $entity_field_item['value'] . '%';
}else{$display_output = ''};

But it just returns the label with no value.

The classic

$display_output = $entity_field_item['value'] . '%';

works fine though.

2 Answers 2

1

Try this:

if ($entity_field_item['value'] != 0)
 {
 $display_output = $entity_field_item['value'] . 'pkt';
 }
 else($display_output = NULL);
1
  • OP wants a display of the value is lower then 0. Your code also works if the value is higher then 0. Commented Dec 29, 2014 at 13:01
0

One issue that I can see is in the if condition $entity_field_item['value'] < '0'

You should remove the quotes from $entity_field_item['value'] < 0 this should make the if condition as expected. But the Label would still be visible.

To remove that you would need to use the patch from the below link

https://drupal.org/node/1928178

1
  • Thanks. I tried $entity_field_item['value'] < 0 without ' ' and the result is all the same. Maybe I need to add something in the "Computed Code" field, rather than "Display Code" field? Also, that patch is for those that don't store in DB. I do.
    – drupalina
    Commented Sep 30, 2013 at 21:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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