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.

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

Steven Buteneers created an issue. See original summary.

jefuri’s picture

Status: Active » Needs review
StatusFileSize
new1.74 KB

Added status checkbox option for entities that implement EntityPublishedInterface.
The chosen setting is applied in the form submit on the duplicate.

jurcello’s picture

Status: Needs review » Reviewed & tested by the community

This looks ok to me.

vpeltot’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Thanks 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:

  • Allow / disallow the status overwrite
  • If status overwrite is allowed: Allow / disallow the display of form element in the clone form
  • If form element is displayed: Set the default value

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.

hanan alasari’s picture

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

hanan alasari’s picture

I have attached the following patch which contain adaption of making status functionality working for all the translation versions of the cloned node.

nachosalvador’s picture

Hello,

last patch(#6) works like a charm but doesn't apply with the last dev version.

Just rerolled it.

nachosalvador’s picture

Status: Needs work » Needs review
Issue tags: +Needs subsystem maintainer review
StatusFileSize
new5.16 KB
new4.87 KB

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

ngkoutsaik’s picture

Hi,

thanks for the patch. I tested it on the latest branch and it works as intended.

ngkoutsaik’s picture

Status: Needs review » Reviewed & tested by the community
kkohlbrenner’s picture

Status: Reviewed & tested by the community » Needs review

The 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

garethhallnz’s picture

Unfortunately, this patch no longer applies against beta6

garethhallnz’s picture

Status: Needs review » Needs work
guilhermevp’s picture

Status: Needs work » Needs review
StatusFileSize
new4.32 KB

Re-rolled patch #8.

Ivan Liaskov’s picture

Patch #14 applies alright, checkbox is there, but it does nothing. Publish status of the cloned entity is equal to the original entity.

guilhermevp’s picture

StatusFileSize
new5.55 KB

Sorry I posted an incomplete patch. Here is the working one.

Ivan Liaskov’s picture

Patch #16 is working. Thank you very much.

marcusvsouza’s picture

Status: Needs review » Reviewed & tested by the community

The patch applies properly and work as expected!

steven buteneers’s picture

+1 RTBC, please get this in the next release

leon kessler’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new5.54 KB

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

avpaderno’s picture

rade’s picture

Status: Needs review » Needs work
+++ b/src/Form/EntityCloneForm.php
@@ -64,6 +67,20 @@ class EntityCloneForm extends FormBase {
+  protected $moduleHanlder;

Typo in $moduleHanlder, should be $moduleHandler

rade’s picture

Status: Needs work » Needs review
StatusFileSize
new5.54 KB

Fixed typo mentioned in #22, patch attached.

nicolas s.’s picture

Patch #23 works for me with a Drupal 9.3

Rajeshreeputra made their first commit to this issue’s fork.

igork96’s picture

Status: Needs review » Reviewed & tested by the community

Working nicely with Drupal 9.4. Marking this as RTC.

interactivex’s picture

StatusFileSize
new5.7 KB

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

rajeshreeputra’s picture

Version: 8.x-1.x-dev » 2.x-dev

@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?

  • Rajeshreeputra committed fda88de5 on 2.x
    Issue #3036068 by Rajeshreeputra, nachosalvador, guilhermevp, hanan...
rajeshreeputra’s picture

Status: Reviewed & tested by the community » Fixed

Thank you for working on this, merged, release will follow shortly.

  • Rajeshreeputra committed 45b559be on 8.x-1.x
    Issue #3036068 by Rajeshreeputra, nachosalvador, guilhermevp, hanan...

Status: Fixed » Closed (fixed)

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

pumpkinkid2’s picture

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

logeshvaran’s picture

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