Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I have two content types: cars and mileage. Car nodes have an integer field (field_mpg) and mileage nodes have an integer field (field_miles) and a node reference (field_car) . Mileage also has a computed field (field_gas_used).
I would like to use a Computed Code similar to:
$gas_used = $entity->field_mpg[LANGUAGE_NONE][0]['value']) * $entity->field_miles[LANGUAGE_NONE][0]['value']);
$entity_field[0]['value'] = $gas_used;
This give the error:
Notice: Undefined property: stdClass::$field_mpg in eval() (line 15 of /var/www/html/drupal-7.2/sites/all/modules/computed_field/computed_field.module(439) : eval()'d code).
It kind of makes sense because $field_mpg is not defined for mileage nodes.
Is there a work around?
Comments
Comment #1
waverate CreditAttribution: waverate commentedSolution is #189976: Node Object from node reference field?.
Example below updated for D7.
Comment #3
TTNT CreditAttribution: TTNT commentedI can't get this to work in D7. Is there anyone who did? Or maybe someone has another idea as to how we can use fields within referenced content? Thanks!