I understand that I can append values to an entity reference field to a node normally with this method
$node->field_tags[] = [ 'target_id' => $my_id, ]; However I have a function like so
function addTag($node,$field,$id){ $node->set($field,[ 'target_id' => $id, ]); } In other words I have to anticipate any field the user supplies. Looking at the node class here
https://api.drupal.org/api/drupal/core!modules!node!src!Entity!Node.php/class/Node/8.2.x
I did discover the set function that lets me specify a field and a value but I don't believe that this would append to an array of entities in a field.
How would I append to an entity reference field to a node if the field name is supplied in a variable?
$node->{$field}[] = ..., but I wouldn’t be surprised if the API offered something more pleasing