Need a bit of advice on Computed Field

189 views
Skip to first unread message

Paul Woodhead

unread,
Jan 25, 2013, 11:05:09 AM1/25/13
to nw...@googlegroups.com
I'm trying to create a computed field: field_commisson_pot (i know commission is spelled wrong, but that's now the machine name for the field), but i'm not getting any output or displayed field at all, no errors, just nothing. Computed code - $entity_field[0]['value'] = (($entity-> field_monthly_premium[0]['value']) *12*170/100); and display code just the default - $display_output = $entity_field_item['value']; Has anyone got any suggestions why this isn't displaying any value? Computed code - $entity_field[0]['value'] = (($entity-> field_monthly_premium[0]['value']) *12*170/100); and display code just the default - $display_output = $entity_field_item['value']; Has anyone got any suggestions why this isn't displaying any value? 

Philip Norton

unread,
Jan 25, 2013, 11:30:04 AM1/25/13
to nw...@googlegroups.com
I've got no idea as I've never used that module. But if I was in your position I would be looking at xdebug to see what was going on behind the scenes to display nothing. It's probably a simple 'if' statement that is throwing away the output, but finding out exactly what that is can be a pain.

I'm willing to show you how to get xdebug working at the next meetup!

Phil


On 25 January 2013 16:05, Paul Woodhead <pa...@noworriesit.co.uk> wrote:
I'm trying to create a computed field: field_commisson_pot (i know commission is spelled wrong, but that's now the machine name for the field), but i'm not getting any output or displayed field at all, no errors, just nothing. Computed code - $entity_field[0]['value'] = (($entity-> field_monthly_premium[0]['value']) *12*170/100); and display code just the default - $display_output = $entity_field_item['value']; Has anyone got any suggestions why this isn't displaying any value? Computed code - $entity_field[0]['value'] = (($entity-> field_monthly_premium[0]['value']) *12*170/100); and display code just the default - $display_output = $entity_field_item['value']; Has anyone got any suggestions why this isn't displaying any value? 

--
 
 
 

Paul Woodhead

unread,
Jan 25, 2013, 11:47:24 AM1/25/13
to nw...@googlegroups.com
Cheers Phil, that'd be excellent ;) I've got xdebug installed on my netbeans, but don't really know what to do with it :/ 


--
 
 
 



--
Paul H. Woodhead
No Worries IT Ltd
Cariocca Business Park
Suite 72
2 Sawley Rd
Manchester
M40 8BB
Tel: 0161 4088 997
Mob:07791 385151

James Bisset

unread,
Jan 25, 2013, 11:52:13 AM1/25/13
to nw...@googlegroups.com
A while since i've used computed field, but don't you have to get the data from somewhere first? Like the first line should ask for the $node or something?

I have vague memories (ain't that the truth) of working out the age from the DOB of a user, and having to go and get $user first.


Jim

--
m e d i a c h r o m e
+44 (0) 161 872 7272
http://www.mediachrome.com

VAT reg: 748 6096 90
> --
>
>
>

Will Wade

unread,
Jan 25, 2013, 11:47:31 AM1/25/13
to nw...@googlegroups.com
Not sure but having played extensively with computed code since D5..Make sure that the $entity->field_monthly_premium[0]['value'] is actually exists and is an int and not something else..

Try this for size.. instead - a bit neater..
$entity_field[0]['value'] = ($entity->field_monthly_premium[0]['value'] *20.4);

As a quick hack see if und works.. so..
$entity_field[0]['value'] = ($entity->field_monthly_premium['und'][0]['value'] *20.4);

My recommendation is to turn on development modules and look at the node information - see how it looks. I'm guessing you have it storing in the database right?

w

On 25 Jan 2013, at 16:05, Paul Woodhead <pa...@noworriesit.co.uk> wrote:

> I'm trying to create a computed field: field_commisson_pot (i know commission is spelled wrong, but that's now the machine name for the field), but i'm not getting any output or displayed field at all, no errors, just nothing. Computed code - $entity_field[0]['value'] = (($entity-> field_monthly_premium[0]['value']) *12*170/100); and display code just the default - $display_output = $entity_field_item['value']; Has anyone got any suggestions why this isn't displaying any value? Computed code - $entity_field[0]['value'] = (($entity-> field_monthly_premium[0]['value']) *12*170/100); and display code just the default - $display_output = $entity_field_item['value']; Has anyone got any suggestions why this isn't displaying any value?
>
> --
>
>
>

Paul Woodhead

unread,
Jan 25, 2013, 11:58:18 AM1/25/13
to nw...@googlegroups.com
Hi Jim,
$entity_field has replaced $node_field in 7. I'm calling field_monthly_premium as my data, but alas, nowt :/
Cheers,
Paul


--



Paul Woodhead

unread,
Jan 25, 2013, 12:12:56 PM1/25/13
to nw...@googlegroups.com
Cheers Will,
Much tidier maths, and also the field_monthly_premium is a decimal.  I have also checked the DB and the new computed field is there, but contains no data.  So, do I need to either make the field_monthly_premium an int, or change my computed code to reflect that it's a decimal?
Cheers,
Paul


--



Paul Woodhead

unread,
Feb 6, 2013, 10:47:16 AM2/6/13
to nw...@googlegroups.com
Hi All,
I've got the output to display, but I'm also getting:

Strict warning: Only variables should be passed by reference in eval() (line 1 of /home/paul/public_html/nowo/sites/all/modules/computed_field/computed_field.module(466) : eval()'d code).

The computed code is:
$entity_field[0]['value'] = array_pop(array_pop(field_get_items($entity_type, $entity, 'field_monthly_premium')))*20.4;
and display code is the default...."$display_output = $entity_field_item['value'];"  Where is the & that i'm getting a strict ticking off about? :/

Cheers,
Paul

Paul Woodhead

unread,
Feb 6, 2013, 12:43:12 PM2/6/13
to nw...@googlegroups.com

Pushed it to the live site under duress, and no error. So must be something to do with my local environment ;)

--
 
---
You received this message because you are subscribed to the Google Groups "NWDUG" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nwdug+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Stephen Mount

unread,
Feb 6, 2013, 4:15:44 PM2/6/13
to nw...@googlegroups.com
This may be because 'live' has error reporting muted/turned off. Check your php.ini file on live.

6 February 2013 17:43

Pushed it to the live site under duress, and no error. So must be something to do with my local environment ;)

--
 
---
You received this message because you are subscribed to the Google Groups "NWDUG" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nwdug+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
25 January 2013 16:30
I've got no idea as I've never used that module. But if I was in your position I would be looking at xdebug to see what was going on behind the scenes to display nothing. It's probably a simple 'if' statement that is throwing away the output, but finding out exactly what that is can be a pain.

I'm willing to show you how to get xdebug working at the next meetup!

Phil



--
 
 
 
25 January 2013 16:05

Paul Woodhead

unread,
Feb 7, 2013, 4:58:18 AM2/7/13
to nw...@googlegroups.com
Cheers Stephen for the heads up....Just checked and it's all turned on, and I can create error messages by deliberately changing the code....So, fingers crossed, it seems to have worked ;)
postbox-contact.jpg
postbox-contact.jpg

Elliot Ward

unread,
Feb 7, 2013, 5:27:01 AM2/7/13
to nw...@googlegroups.com
Or a different version of PHP between environments? IIRC this didn't use to raise a warning.

On 6 February 2013 21:15, Stephen Mount <stephe...@sm5.ltd.uk> wrote:
postbox-contact.jpg
postbox-contact.jpg

Paul Woodhead

unread,
Feb 7, 2013, 7:58:57 AM2/7/13
to nw...@googlegroups.com
There is Eli: 5.4 local and 5.3 production ;)
postbox-contact.jpg
postbox-contact.jpg

Paul Woodhead

unread,
Apr 16, 2013, 7:40:43 AM4/16/13
to nw...@googlegroups.com
Hi Will,
A belated thanks for the advice: I got computed field working beautifully using array_pop and your tidy sum.  However, I am interested in how you cancelled that calculation down to that much tidier sum.  Having never been on the receiving end of a formal education, I'm a bit lacking in such grey matter matters.  Is there a easy way to explain how you did that?  I would be eternally grateful if you'd be kind enough to share that knowledge, or point me in the direction of some links that might help me ;)
Cheers,
Paul 

Philip Norton

unread,
Apr 16, 2013, 7:46:20 AM4/16/13
to nw...@googlegroups.com
Hi Paul,

I can see that he took your calculation and worked it out as much as he could before using the filed. The brackets are actually enforcing this as well so they can also be removed when the calculation is made simpler.

Essentially:

$entity_field[0]['value'] = (($entity-> field_monthly_premium[0]['value']) *12*170/100);

20.4 = 12*170/100

$entity_field[0]['value'] = ($entity-> field_monthly_premium[0]['value'] * 20.4);

Phil


Paul Woodhead

unread,
Apr 16, 2013, 7:48:56 AM4/16/13
to nw...@googlegroups.com
Brilliant, and easy when you know how 
Cheers Phil
360.gif

Will Wade

unread,
Apr 16, 2013, 8:08:47 AM4/16/13
to nw...@googlegroups.com
Was a pleasure. (And can see Phil showed the sum so won't repeat it)

Will

Sent from my iPhone. Please excuse brevity and typing errors. 

Paul Woodhead

unread,
Apr 16, 2013, 9:11:01 AM4/16/13
to nw...@googlegroups.com

Cheers though ;) They now have decided to create loads of different commissions based on time periods, insurer, rep, etc.....Good Drupal fun ;)

ja...@sugarcat.co.uk

unread,
Aug 8, 2013, 7:25:43 AM8/8/13
to nw...@googlegroups.com
Paul

Reply all
Reply to author
Forward
0 new messages