Consider making the createCopy config action optionally fail if the entity display already exists

Created on 25 October 2024, 3 months ago

Problem/Motivation

As a follow up for the issue "Entity displays cloning requires special config action" โ†’ and inspired by "Consider making the cloneAs config action optionally fail if the clone already exists" โœจ Consider making the cloneAs config action optionally fail if the clone already exists Active I think it makes sense to ignore the existing entity display if someone tries to copy another entity display into it. This is needed to allow to run recipe multiple time if it has createCopy config action. This will ensure the idempotence of the recipe.

Steps to reproduce

Create a recipe with config action createCopy for some entity display.
Run the recipe.
Try to run the recipe one more time.
Observe the error similar to this:

'entity_view_display' entity with ID 'node.page.search_index' already exists.

Proposed resolution

In method createCopy of EntityDisplayBase first try to load the entity display with new view mode and only if it doesn't exist do the duplicate. Field UI module does the check earlier in the form class core/modules/field_ui/src/Form/EntityDisplayFormBase.php:

          if (!$this->entityTypeManager->getStorage($this->entity->getEntityTypeId())->load($this->entity->getTargetEntityTypeId() . '.' . $this->entity->getTargetBundle() . '.' . $mode)) {
            $display = $this->getEntityDisplay($this->entity->getTargetEntityTypeId(), $this->entity->getTargetBundle(), 'default')->createCopy($mode);
            $display->save();
          }

This makes sure that the copy doesn't exist. But in config action this is not done.

Remaining tasks

Add check in createCopy method

User interface changes

None

Introduced terminology

None

API changes

None

Data model changes

None

Release notes snippet

createCopy config action will be ignored if the target entity display already exists.

โœจ Feature request
Status

Active

Version

10.4 โœจ

Component

recipe system

Created by

๐Ÿ‡ฉ๐Ÿ‡ชGermany a.dmitriiev

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024