Ran into an issue with sites that have the Domain Access module installed. Domain Access has an entity reference field that targets the domain config entity. When you clone a node you get the choice to automatically clone the target config entity (in this case domain records) for the Domain Access field. This seems to be the kind of thing you would only want do with very careful consideration.
Given that the Entity Clone settings form purposefully excludes Config Entities, seems like a bad idea to allow a user to clone the target config entities.
Patch attached here. This patch will skip over Entity Reference field that are targeting Config Entities when the clone tab is visited on an entity.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | entity_clone-clone_config_entity-3037470-9.patch | 2.92 KB | vpeltot |
Comments
Comment #2
pdenooijer commentedWorks like a charm!
Comment #4
mcgettrs commentedThe current patch appears to break entity clone for nodes with nested entities like paragraphs. With this patch 1 installed the paragraph entities were not getting cloned at all. The original and cloned node then have references to the same paragraphs.
The patch appears to be missing a use statement.
use Drupal\Core\Entity\ContentEntityTypeInterface;This is causing entity clone to hit the 'continue' on every iteration of the for loop. I have attached a patch that includes this use statement and it appears to fix the non cloning issue for me
Comment #5
pdenooijer commentedArgh that I missed the use statement. Tested this patch with xdebug and it works like it should. Does not blow up on config entities and does clone nested content entities.
Comment #6
pdenooijer commentedFound an even better solution, this will filter out all unknown types. Bonus of this patch is that it will make sure very big entities will not run out of memory if you only deep clone a limited set of entity types. Had to update the default EntityCloneSettingsManager::getHiddenValue() to TRUE to make sure unknown types don't blow up the form.
Please have a look at the patch.
Comment #7
laravz commentedYou could replace this with "return $form_settings[$entity_type_id]['hidden'] ?? TRUE" since php 7 has to be used now
Though it looks fine to me in general and the patch has been working successfully in our setup.
Comment #8
laravz commentedComment #9
vpeltot commentedI prefer the patch #4 approach.
Rather than using the clone settings to know if we can clone a reference or not (here ConfigEntity), IMHO it is necessary to be more basic and not authorize the recursive clone of the config entity referenced in a content entity.
@pdenooijer
To avoid memory limit when cloning a big entity containing a lot of child entities, this issue #3010626: Sub-entity cloning has unnecessary recursion for form causing memory issues cover this bug.
Comment #11
vpeltot commentedCommited !
Thanks.