0

I am learning Drupal 7 computed field. According to web sources they say i should use $entity instead of $node for Drupal 7.

I have a content type product with custom fields field_price and field_discount. I need a computed field field_finalprice = field_price - field_discount.

As a first step I am just trying to assign field_discount to my finalprice so I created a computed field with code

$entity_field[0]['value'] = array_pop(array_pop(field_get_items($entity_type, $entity, 'field_discount')));

I do not get any value. Please provide any links that uses computed field for drupal 7.

JJJ
  • 32,902
  • 20
  • 89
  • 102
Balaji
  • 31
  • 2
  • 4

1 Answers1

1

There is an update in the comments IIRC http://drupal.org/node/1271050

$entity_field[0]['value'] = $entity-> field_price[LANGUAGE_NONE][0]['value'] - $entity-> field_price[LANGUAGE_NONE][0]['value']

should work

EdChum
  • 376,765
  • 198
  • 813
  • 562
Ranko
  • 111
  • 1