I'm attempting to programmatically create test users in Drupal 8 via hook_update_n()
. I have an array of user attributes I'm using to create users.
I've got three fields added to the User entity that add term references to existing vocabularies that have been populated with terms. Two of these fields store a single term reference, while the third can store multiple term references.
I've retrieved the term object using this code.
$term = \Drupal::entityTypeManager()
->getStorage('taxonomy_term')
->loadByProperties(['name' => $user['bu'], 'vid' =>
'tx_business_unit']);
I'm trying to add a term reference to my user field, called "user_bu".
I've attempted to use the solution given on Programmatically update an entity reference field, but it doesn't work for me.
Everything else on my user record is being populated without issue.