By submitting patches for review, you agree to the Developer Certificate of Origin. A copy of this agreement can be found in the project root, named CONTRIBUTING.txt.

Problem/Motivation

When enabling translation for a content type, the following exception is produced:

TypeError: Drupal\Core\Entity\EntityBase::getOriginal(): Return value must be of type ?Drupal\cached_moderation_state\HiddenFieldConfig, Drupal\field\Entity\FieldConfig returned in Drupal\Core\Entity\EntityBase->getOriginal() (line 697 of /app/web/core/lib/Drupal/Core/Entity/EntityBase.php).
#0 /app/web/modules/contrib/cached_moderation_state/src/HiddenFieldConfig.php(27): Drupal\Core\Entity\EntityBase->getOriginal()
#1 /app/web/core/modules/field/src/Entity/FieldConfig.php(182): Drupal\cached_moderation_state\HiddenFieldConfig->getOriginal()
#2 /app/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(567): Drupal\field\Entity\FieldConfig->preSave(Object(Drupal\field\FieldConfigStorage))
#3 /app/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(522): Drupal\Core\Entity\EntityStorageBase->doPreSave(Object(Drupal\cached_moderation_state\HiddenFieldConfig))
#4 /app/web/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php(239): Drupal\Core\Entity\EntityStorageBase->save(Object(Drupal\cached_moderation_state\HiddenFieldConfig))
#5 /app/web/core/lib/Drupal/Core/Entity/EntityBase.php(370): Drupal\Core\Config\Entity\ConfigEntityStorage->save(Object(Drupal\cached_moderation_state\HiddenFieldConfig))
#6 /app/web/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php(635): Drupal\Core\Entity\EntityBase->save()

Steps to reproduce

// Load some moderated entity.
$entity = \Drupal\node\Entity\Node::load(1);

// Attempt to update the cached_moderation_state field definition.
$field_definition = $entity->getFieldDefinition('cached_moderation_state');
$field_definition->save();

Proposed resolution

Override the definition of EntityBase::setOriginal() to always convert the original entity to the static type.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

clayfreeman created an issue. See original summary.

  • clayfreeman committed a26fcdc4 on 1.2.x
    feat: #3578590 Error in EntityBase::getOriginal() when enabling content...

  • clayfreeman committed 05435c2f on 1.1.x
    feat: #3578590 Error in EntityBase::getOriginal() when enabling content...
clayfreeman’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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