WebTechKitchen; Your Web Technology Kitchen, contact us to create, or maintain your websites and other digital properties.

Programmatically add an entity reference field or a role

Submitted by barnettech on Tue, 11/02/2021 - 15:49

For a multiple-value field, to add the value to the end of the list, use the following code.

$node->field_code_used_by[] = ['target_id' => $user_id];

For a single use

$group_content1->group_roles->target_id = $role_id