Error: Call to undefined method Drupal\Core\Field\BaseFieldDefinition::createDuplicate()

Created on 28 March 2023, almost 2 years ago

Problem/Motivation

I'm getting following error when trying to clone a content type:

Error: Call to undefined method Drupal\Core\Field\BaseFieldDefinition::createDuplicate() in Drupal\content_type_clone\Form\CloneContentType::cloneContentTypeField() (line 67 of /app/web/modules/contrib/content_type_clone/src/Form/CloneContentType.php).

Working with Drupal 9.4.3

This method doesn't seem to exist: https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Field!BaseFieldDe...

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇧🇪Belgium ludo.r Brussels

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @ludo.r
  • First commit to issue fork.
  • @ranjit1032002 opened merge request.
  • 🇧🇪Belgium ludo.r Brussels

    It appears that this happens with content_moderation module enabled, on the moderation_state field.

    For now I circumvented this issue like this:

        // Clone the field.
        $original_field = $data['field'];
        if (method_exists($original_field, 'createDuplicate')) {
          // Do stuff.
        }
    
  • Status changed to Needs work 9 months ago
  • 🇨🇭Switzerland redzeuf Geneva

    I had the same issue with module "Content Moderation" enabled and this fix works for me.
    Needs to contrib the patch files.

  • First commit to issue fork.
  • Merge request !3Update file CloneContentType.php → (Open) created by immaculatexavier
  • Merge request !4Resolve #3350851 → (Open) created by immaculatexavier
  • Status changed to Needs review 9 months ago
  • 🇺🇸United States selwynpolit

    I applied this MR and it worked fine for me. I didn't dig into any side effects this may have on Content Moderation. It does report that a field could not be cloned because the createDuplicate method does not exist. I suspect it isn't really an issue though.

  • 🇺🇸United States jnicola

    Same issue for us at USDOJ:

    Call to undefined method Drupal\Core\Field\BaseFieldDefinition::createDuplicate() in Drupal\content_type_clone\Form\CloneContentType::cloneContentTypeField() (line 67 of modules/contrib/content_type_clone/src/Form/CloneContentType.php).

    This MR fixed the issue, though there was a drupal message stating:

    "The field moderation_state cannot be cloned because the createDuplicate method does not exist."

    Perhaps expected, and everything worked for the most part so.. good to go?

  • 🇺🇸United States jnicola

    Marking as reviewed and tested by the community. Enough folks have weighed in on this one, it's good to go and improves the module.

Production build 0.71.5 2024