I have node 1 has a reference to node 2 & node 3 how can I make node 2 & node 3 have a reference automatically (because they have the same reference with node1)?
2 Answers
You can implement hook_entity_insert()
Act on entities when inserted.
Parameters
$entity: The entity object.
$type: The type of entity being inserted (i.e. node, user, comment).
and inside the hook check if you have more than one node in the reference field, in this case you will edit all the nodes and add the reference to the others.
-
Thank you so much !! but I'm not sure how can I do that ? i'm new to The hooks & that stuff??– MohKCommented Jun 21, 2017 at 20:05
-
@MohK Well, you will need to write a little module to do this. Commented Jun 21, 2017 at 20:17
-
You can find a solution that works for me on the following pages: https://www.drupal.org/project/prepopulate/issues/2668010 it is using the module prepopulate and you can find the documentation on this module page.
An other solution is proposed by using the business rule module.