I have tried to display the flag with the computed field but I did not work..
I filled out the field Computed Code (PHP):

$entity_field[0]['value'] = "";

And Display Code (PHP):

$display_output = flag_create_link('product_comparison', $node->nid);

But at the node I get the errors:

* Notice: Undefined variable: node at function eval() (line 1 at file /home/111/sites/all/modules/computed_field/computed_field.module(318) : eval()'d code).
* Notice: Trying to get property of non-object at function eval() (line 1 at file /home/111/sites/all/modules/computed_field/computed_field.module(318) : eval()'d code).

And Flag link is displayed, but does not work.

Comments

webroru’s picture

Assigned: webroru » Unassigned

I noticed if instead of "$ node-> nid" indicate clearly the number node (for example

$display_output = flag_create_link('product_comparison', 1);

), the errors disappear and flags start working for this node.

webroru’s picture

I got it!
To get 'nid' in the computed field is necessary to do: $entity->nid;

webroru’s picture

Status: Active » Closed (fixed)
mgriebe’s picture

That you can use computed field to attach a create flag link to an entity should be added to the documentation.