Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By MircoDrupal on
In Drupal 8 (8.7.6), I would need to import several terms in a taxonomy dictionary. It is easy to create the terms at the “root” level, but when I try to create a term with a parent, the term is not created under the parent (but in the root).
Do you have any idea on how to solve the issue?
Thanks
Comments
Not sure what you mean by
Dear Sam711,
Dear Sam711,
thank you for your answer. I would need to use the REST Api (as explained on https://www.drupal.org/docs/8/core/modules/rest/3-post-for-creating-cont...), but if I do not find a solution soon, I will use your approach.
Best regards,
I understand now. So,
I understand now. So, following the Guzzle example, as the parent is an entity reference you could do something like this.
$serialized_entity = json_encode([
'name' => [['value' => 'new_term_name']],
'vid' => [['target_id' => 'your_taxonomy']],
'parent' => [['target_id' => $root_term->id()]],
]);
Solution Found
I figured out the solution: it is necessary to send the parent UUID.
This is the complete JSON request: