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.

Comments

mattsqd created an issue. See original summary.

mattsqd’s picture

mattsqd’s picture

Status: Active » Needs work
pier56’s picture

Thank you ! That saved me some times !
I had the same issue on a blank drupal website. Please consider this patch.
Best regards,
Pierre

nathan tsai’s picture

#2 Also worked for me.

kburakozdemir’s picture

#2 works for me.

eworwa’s picture

Patch in #2 worked for me.

vuil’s picture

Version: 8.x-1.3 » 8.x-1.x-dev
Status: Needs work » Reviewed & tested by the community

I set the issue to RTBC. It is ready to be committed to the latest 8.x-1.x-dev branch. Thank you.

  • vuil committed f9f2f92 on 8.x-1.x
    Issue #3022090 by mattsqd, Chris Happy, kburakozdemir, eworwa, pier56,...
vuil’s picture

Status: Reviewed & tested by the community » Fixed

Committed and fixed. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.