I was wondering if it is possible to get the field value from an existing node and use it in the computed field of a new node.

Example: Get the value of the Field_age from node A, to be used in Node B, and add 2 years to it.

Node A
Field_age
Field_location

Node B
Field_age (from Node A) + 2

Comments

Houmanvg created an issue. See original summary.

colan’s picture

Version: 8.x-2.0-alpha4 » 8.x-2.x-dev
Priority: Critical » Normal
diamondsea’s picture

How will you know what node A is? Is it always the same NID? Or an entity reference?

Pseudocode version would for the computed field in Node B would probably be something like:

In the code for the computed field on Node

$node_a_nid = 1234;  // if this is a fixed NID
$node_a = node_load($node_a_nid);  // load Node A
$age = $node_a->field_age->value + 2;
return $age;

or if you're using an entity reference field to link the two, something like this:

$age = $entity->field_node_a_entityreference->entity->field_age->value + 2;
return $age;
dqd’s picture

Title: get field value from another node » How to get field value from another node
Version: 8.x-2.x-dev » 8.x-2.0-alpha4

? ... Sorry I don't get the issue maintainer change of the version status. This is a support request, so how reasonable is it to change the project version affected set by the reporter here? It is not about a new feature or patch to apply to a newer dev version or something. The question belongs to the version the user uses and this should be the version the issue belongs to.