I have created 2 Content entities. Entity A has an "Entity Reference Field" with multiple values to Entity B. This all work as expected.

What I want to achieve is, to create a link from Entity B page, that when the user clicks on it, it will be added (appended) to Entity A "Entity Reference Field".

What's the best way to get this done?

  • (I know I can use the Flag and Flag lists module, but there are limitations to it like it will be impossible/difficult to make these lists public/anonymous. After trying Flag lists out, it also didn't feel like a very Drupal native approach.)
  • (Getting a list of referenced items etc. is an other challenge, but my biggest problem is to get the linking approach working first.)
  • I have some ideas, but would like more info. When you say "a link," what would that be like? Your description sounds like a checkbox, which I don't quite get.
    – beltouche
    Jan 20, 2022 at 14:17
  • I mean like a real href link: <a href="Entity_A">Entity A</a>
    – cateye
    Jan 20, 2022 at 14:20
  • That blows my ideas out of the water. My inclination is to trigger an AJAX call to some custom endpoint with A & B as parameters and have the endpoint load up entity A, add the reference as necessary, and resave. Someone else here I'm sure can fill in the gaps more readily than I.
    – beltouche
    Jan 20, 2022 at 14:25

1 Answer 1


The direction I'm trying to take is, to add the reference with:

$node->{$target_field}[] = $id; 

But I'm struggling to figure out how to create this custom form that will be displayed on the node view.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.