When copying a vocabulary, I receive this error:
Error: Call to undefined method Drupal\Core\Field\BaseFieldDefinition::createDuplicate() in Drupal\entity_type_clone\Form\CloneEntityTypeData::cloneEntityTypeField() (line 30 of {absolute path to module}/entity_type_clone/src/Form/CloneEntityTypeData.php)
I tracked it down to the 'parent' field on the taxonomy_term entity. I don't pretend to know much about fields and storage but this is what seems to happen:
$field->getTargetBundle()
is called to determine if this is a reference field. Usually this returns nothing for base fields (Drupal\Core\Field\BaseFieldDefinition) but for some reason, the parent field returns the target bundle. However, it is not a base field override (Drupal\Core\Field\Entity\BaseFieldOverride) so it doesn't have access to createDuplicate().
I don't know if it is the proper solution but I just made a special case for taxonomy_term & parent in the conditional. This probably needs a more elegant solution but I'm not very familiar with this code.
I tested out my patch and it skipped trying to copy parent but when the new vocabulary was created, the taxonomy_term__parent table seemed to keep track of parent just fine when I created new terms and sorted them.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | entity_type_clone-error-when-duplicating-parent-field-of-taxonomy_term-entity-3022090-2.patch | 760 bytes | mattsqd |
Comments
Comment #2
mattsqd commentedComment #3
mattsqd commentedComment #4
pier56 commentedThank you ! That saved me some times !
I had the same issue on a blank drupal website. Please consider this patch.
Best regards,
Pierre
Comment #5
nathan tsai commented#2 Also worked for me.
Comment #6
kburakozdemir commented#2 works for me.
Comment #7
eworwa commentedPatch in #2 worked for me.
Comment #8
vuilI set the issue to RTBC. It is ready to be committed to the latest 8.x-1.x-dev branch. Thank you.
Comment #10
vuilCommitted and fixed. Thanks!