Problem/Motivation
Currently when cloning an entity, lets say a node, the published state of the original entity is also cloned. When cloning nodes there is really not a reason for the cloned node to be published directly, because:
- This creates duplicate content.
- The node will for sure have to be edited in the first place. (If not for the "ugly" title only)
- Publishing could also trigger other unwanted actions, a couple of examples could be: Feeds contain the cloned nodes, nodes could be published to social media, etc.
Proposed resolution
Provide the ability to determine the published state of the cloned entity.
It should be configurable what the default value would be, per entity, and possibility even per bundle. In my option it would be logical to have these settings available on the entity type configuration page (f.e. a node type). On the clone form of the entity this option is available, with the default used, but possible to override.
Remaining tasks
- Determine where to configure clone settings for publishing
- Implement solution to allow cloned entities to be unpublished if indicated
- Write a test that proves this works
User interface changes
TBD.
API changes
TBD.
Data model changes
TBD.
Release notes snippet
TBD.
| Comment | File | Size | Author |
|---|---|---|---|
| #27 | entity_clone-3036068-27.patch | 5.7 KB | interactivex |
| #23 | entity_clone-3036068-23.patch | 5.54 KB | rade |
| #20 | entity_clone-3036068-20.patch | 5.54 KB | leon kessler |
| #16 | 3036068-16.patch | 5.55 KB | guilhermevp |
| #14 | 3036068-14.patch | 4.32 KB | guilhermevp |
Issue fork entity_clone-3036068
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
Comment #2
jefuri commentedAdded status checkbox option for entities that implement EntityPublishedInterface.
The chosen setting is applied in the form submit on the duplicate.
Comment #3
jurcello commentedThis looks ok to me.
Comment #4
vpeltot commentedThanks for this first work.
In accordance with remaining tasks:
Determine where to configure clone settings for publishing
Add a new section in "admin/config/system/entity-clone" that list all entity types that allow publishing, and for each:
Implement solution to allow cloned entities to be unpublished if indicated
The patch in comment #2 must be reviewed to use the configuration previously detailed.
Write a test that proves this works
Add a new test class to cover this use case.
Comment #5
hanan alasariIts worked for me, but there is a problem with translated nodes, if i checked the unpublished status for a node in english language during the clone process, the other cloned translated for this node will remain on published. The change will take place just for the cloned node in english.
Comment #6
hanan alasariI have attached the following patch which contain adaption of making status functionality working for all the translation versions of the cloned node.
Comment #7
nachosalvador commentedHello,
last patch(#6) works like a charm but doesn't apply with the last dev version.
Just rerolled it.
Comment #8
nachosalvador commentedI noticed some publishable entities with content translation could be added in this requested featured and do not open a new issue. Is this right?
So, I attached a new patch that includes it.
Comment #9
ngkoutsaik commentedHi,
thanks for the patch. I tested it on the latest branch and it works as intended.
Comment #10
ngkoutsaik commentedComment #11
kkohlbrenner commentedThe following behavior is observed after requiring patch #8 (content translation, content moderation, workflows enabled):
cloning content in draft state with translations (check the checkbox to publish cloned entities). The cloned entity is still in draft, but cloned translations are published.
cloning content in draft state with translations (not checking the checkbox to publish cloned entities), the cloned entity and translations are both in draft
cloning content in published state with translations (not checking the checkbox to publish cloned entities) … the cloned entity and cloned translations are not published
cloning content in published state with translations (checking checkbox to publish cloned entities) ... cloned entity is in draft and translated content is published.
Takeaways:
cloning draft content & checking the checkbox to publish cloned entities only publishes cloned translations.
cloning published content & checking the checkbox to publish cloned entities only publishes cloned translations.
Expected Behavior:
Cloning draft content with translation in draft state (checkbox to publish is checked) --> cloned content and cloned translations are published
Cloning draft content with translation in published state (checkbox to publish is checked) ---> cloned content and cloned translations are published
Cloning draft content with translation in draft state (checkbox to publish is not checked) ---> cloned content and cloned translations are not published
Cloning draft content with translation in published state (checkbox to publish is not checked) ---> cloned content and cloned translations are not published
Cloning published content with translations in draft state (checkbox to publish is checked) ---> cloned content and cloned translations are published
Cloning published content with translations in published state (checkbox to publish is not checked) ---> cloned content and cloned translations are not published
Comment #12
garethhallnz commentedUnfortunately, this patch no longer applies against beta6
Comment #13
garethhallnz commentedComment #14
guilhermevp commentedRe-rolled patch #8.
Comment #15
Ivan Liaskov commentedPatch #14 applies alright, checkbox is there, but it does nothing. Publish status of the cloned entity is equal to the original entity.
Comment #16
guilhermevp commentedSorry I posted an incomplete patch. Here is the working one.
Comment #17
Ivan Liaskov commentedPatch #16 is working. Thank you very much.
Comment #18
marcusvsouza commentedThe patch applies properly and work as expected!
Comment #19
steven buteneers commented+1 RTBC, please get this in the next release
Comment #20
leon kessler commentedLatest patch had a typo in the UI message:
> If the cloned entity should be save as a published entuty.
Updated in latest patch, needs another review.
Comment #21
avpadernoComment #22
rade commentedTypo in $moduleHanlder, should be $moduleHandler
Comment #23
rade commentedFixed typo mentioned in #22, patch attached.
Comment #24
nicolas s. commentedPatch #23 works for me with a Drupal 9.3
Comment #26
igork96 commentedWorking nicely with Drupal 9.4. Marking this as RTC.
Comment #27
interactivex commentedI made a patch which also works with Entity Clone 2.x and also added a condition that when you use the "Content Moderation" module it will go to the "Publish" state whenever you chose to publish the content immediately.
*TODO*
Another form field where you can chose the content moderation state you want it to set.
Comment #29
rajeshreeputra@interactivex for creating another form field where you can chose the content moderation state you want it to set, can we file separate issue and work in that?
Comment #31
rajeshreeputraThank you for working on this, merged, release will follow shortly.
Comment #34
pumpkinkid2 commentedI believe that this feature introduced a bug when cloning custom blocks.
I've updated to 2.0.0-beta3 and when we try to clone a block, the option for "Save cloned Custom block as published" appears.
If left unchecked, the block clones, and seems to work as intended, however, it is not visible to anonymous users. If checked, I receive a server error.
As far as I am aware, there is no "publish" state for custom blocks, so should the option even be available for that entity type? The feature is great for nodes though.
Comment #35
logeshvaran commentedI too face the same issue as the previous comment.
I am using Entity Clone Version (2.0.0-beta2 ) and also the content moderation module. When cloning the existing published content, new cloned content has been created.
But when viewing the original content. It shows "Website Encounter Error". I deleted the newly cloned content and then able to view the original content.
Also, I noticed that If the cloned content is in a draft version, Unable the view the original content. If the cloned content is published then able to view the original Content.