- πΊπ¦Ukraine Ruslan Piskarov Kiev, Ukraine
It can be resolved by custom module.
Apply this patch https://www.drupal.org/project/user_csv_import/issues/3380676 β¨ Allows altering a user during importing Needs review .
Add code like:
/** * Implements hook_user_csv_import_create_user_alter(). */ function custom_module_user_csv_import_create_user_alter(UserInterface &$user, $values): void { if ($user->hasField('field_department') && $values['field_department'] !== '') { $tid = custom_module_create_terms('person_department', [$values['field_department']]); $user->set('field_department', $tid); $user->save(); } } /** * Create the terms. * * @param $vid * @param array $values * * @return array * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException * @throws \Drupal\Core\Entity\EntityStorageException */ function custom_module_create_terms($vid, array $values = []): array { $terms = []; foreach ($values as $value) { if ($value != '') { $term = custom_module_get_tid_by_name($value, $vid); if ($term === FALSE) { $term = \Drupal::entityTypeManager() ->getStorage('taxonomy_term') ->create([ 'parent' => [], 'name' => $value, 'vid' => $vid, ]); $term->save(); } $terms[] = $term; } } return $terms; } /** * Find term by name and vid. * * @param $name * @param $vid * * @return false * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException */ function custom_module_get_tid_by_name($name = NULL, $vid = NULL) { $term = custom_module_get_term_by_name($name, $vid); return !empty($term) ? $term->id() : FALSE; } /** * Get term by name. * * @param $name * @param $vid * * @return false|mixed * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException */ function custom_module_get_term_by_name($name = NULL, $vid = NULL): mixed { $properties = []; if (!empty($name)) { $properties['name'] = $name; } if (!empty($vid)) { $properties['vid'] = $vid; } $terms = \Drupal::entityTypeManager() ->getStorage('taxonomy_term') ->loadByProperties($properties); $term = reset($terms); return !empty($term) ? $term : FALSE; }