Sorry, this is a super stupid problem but I'm new to PHP and can't solve it myself.

On my node I have an energy field and a computed field. The computed field is supposed to read out the node's current energy, plug it into a function and return another value.

I have tried all of

float( $entity->field_energy ),
float( $entity->field_energy[0]['value'] ), and
float( array_pop(array_pop(field_get_items($entity_type, $entity, 'field_energy'))) )

to read out the node's current energy, but everythings gives me an error. When I replace the reading-out-formulas with a static number everything works fine.

Can anyone tell me how to read out the energy and turn it into a real number?

Comments

jaxxed’s picture

Sorry for the delay,

If you are still looking working on your problem, this will give you a hard to read, but output of the variable.


drupal_set_message(  'ENERGY FIELD:' . var_export( $entity->field_energy , true ) );

If you have the devel module installed, this would be much easier to read:


dpm( $entity->field_energy , 'ENERGY FIELD:' );

I can't rememeber if Radioactivity uses a straight 'value' field value, but quickly looking at your question, I would say that your float() syntax is not right. PHP doesn't cast using such functions.

$energy = (float)$energy->field_energy[0]['value'];
semei’s picture

Status: Active » Closed (fixed)

Thank you! I ended up getting $entity->field_energy['und'][0]['radioactivity_energy'] to work.