Timeline for Easy PHP, Radioactivity module: Read out a node's current energy?
Current License: CC BY-SA 3.0
7 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Oct 2, 2012 at 2:29 | comment | added | Emil Orol | try: floatval($entity->field_energy['und'][0]['radioactivity_energy']) | |
Oct 1, 2012 at 17:59 | vote | accept | deinqwertz | ||
Oct 1, 2012 at 17:58 | comment | added | deinqwertz |
Thanks for your help guys! This worked perfectly. I used print_r to display the field_energy array and noticed that the values are not stored with integer keys but rather with text keys. It turned out that I have to use $entity->field_energy['und'][0]['radioactivity_energy'] . For some reason applying float() to this gives me an error though. But if I don't apply float() I can still use the value as a real number.
|
|
Oct 1, 2012 at 15:30 | comment | added | joedougherty |
In addition, you can download/enable the [Devel Module] (drupal.org/project/devel) and call kpr() on your $node or $entity object. This is functionally the same as calling print_r , but provides a nicer output style.
|
|
Oct 1, 2012 at 13:58 | comment | added | NenadP | redhatlab, excellent remark, i read from default value for simplicity (no language iterations), but your approach is better. Though, one could search through documents and replace all occurances of ['und'] when switching to multilanguage :D | |
Oct 1, 2012 at 13:30 | comment | added | Emil Orol | Just to avoid future issues with translations or new languages setup use it like this: float($node->field_energy[$node->language][0]['value']); | |
Oct 1, 2012 at 13:10 | history | answered | NenadP | CC BY-SA 3.0 |