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.
The description has strange example with double array_pop.
array_pop(array_pop(field_get_items($entity_type, $entity, 'field_a')))
It will generate something like this: Strict warning: Only variables should be passed by reference in eval() (line 3 of ...\modules\computed_field\computed_field.module(399) : eval()'d code).
Here is working example:
$entity_field[0]['value'] =
field_get_items($entity_type, $entity, 'field_a')[0]['value'] /
field_get_items($entity_type, $entity, 'field_b')[0]['value'];
Comments
Comment #1
core44 CreditAttribution: core44 commentedThanks for this, caught me out for a while!
Comment #2
bkirkendall CreditAttribution: bkirkendall commentedThanks! You saved me so much agony!
Comment #3
sardbaba CreditAttribution: sardbaba commentedThanks!
Comment #4
break9 CreditAttribution: break9 commentedto avoid php notices this should be written as:
Comment #5
arruk CreditAttribution: arruk commentedhow would this be used to total a single field with multiple values?
Comment #6
kiricou CreditAttribution: kiricou commentedthanks !!!
Comment #7
colanOkay, I think I got this fixed on the doc page over at https://www.drupal.org/node/126522. Please review.
Comment #8
colanJust committed this to the in-line example as well. Thanks!
Comment #10
colanI'll assume this is fixed for now. Speak up if there are any issues.
Comment #12
jaredcampbell CreditAttribution: jaredcampbell commentedAre there any plans to push this fix to the production version of this module for Drupal 7?
Edit: I misunderstood the post... Will be updating my code to eliminate the double array pop. Thanks!
Comment #13
colanThanks for the idea. We needed another D7 release anyway. Please find this fix in 7.x-1.1. It should be published in the next few minutes.
Comment #14
siramsay CreditAttribution: siramsay as a volunteer commentedI couldn't get this working using the example code but were getting the Strict warning: Only variables should be passed by reference in eval()
I am working with 5 star fields and this code works, just posting for others experiencing the same problem and maybe someone can optimize it a bit?
it passes variables to the array_pop function and does it twice, or does double array_pop as the issue describes .
running PHP 5.5.30