I need to update my referential entity with new values that are inserted every time a user visits the page. I tried to use this code but unfortunately, the latter does not add a value but replaces all of them. I am attaching the code that I used in the hope that someone can help me with this problem. thank you
nodeObj = Node::load(implode($nids));
$nodeObj->set('my_field', $current_user_id);
$nodeObj->save();
If I understand your issue correctly, your code is overwriting the entire value of
my_fieldrather than appending a new value. Also, theimplode()and the$nidsvariable suggest to me that you may be trying to perform this function on multiple nodes at once, which your current code will not do.my_fieldis an ItemList field of some kind.