Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 294476

EntityDisplayBase::createCopy() naïvely assumes that the duplicate doesn't already exist

$
0
0

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" 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.


Viewing all articles
Browse latest Browse all 294476

Trending Articles