Problem/Motivation

Per issue https://www.drupal.org/project/entity_clone/issues/2724939, the created date of the cloned entity becomes the current date. Though the last modified date stays the same as the original entity, which is before the cloned entity's created date (in theory not even possible). This should also be the current date.
Another annoying side effect is that the newly created entity appears somewhere down the content list in the admin overview, instead of on top like every other new content item.

Steps to reproduce

Clone for example an old node (with old last-modified date) and afterwards search for it in the content view /admin/content. You won't find it on top of the list like it should, because the list is sorted by the last modified date.

Proposed resolution

While cloning the entity, set its last modified date to the current date, just like the created date. Perhaps make it a setting so we can choose the behaviour.

Remaining tasks

  1. Write a patch
  2. Review and feedback
  3. RTBC and feedback
  4. Commit
  5. Release

User interface changes

None, unless extra settings are provided.

API changes

None.

Data model changes

None.

Comments

Fernly created an issue. See original summary.

guilhermevp’s picture

Assigned: Unassigned » guilhermevp
guilhermevp’s picture

Status: Active » Needs review
StatusFileSize
new3.61 KB

Created a patch for it, but it doesn't have test yet, just want to know if this is exactly what you want.

fernly’s picture

Thanks for the quick response. Very good that it's optional and it does what this issue was requesting.

A remark concerning the concept:

  • If we make 'resetting the modified date' optional, wouldn't it make more sense to make the created date optional together with the modified date? The modified date should always be equal or later than the created date anyways. So seeing this patch, I would change the option to "Set the created and modified date to the current date" (or something similar to that). I can imagine that some cases require both dates to stay the same. But never to have an updated 'created date' and an optional old 'last modified' date. My 2 cents.

Some small styling remarks:

  1. +++ b/src/EntityClone/Content/ContentEntityCloneBase.php
    @@ -112,6 +112,11 @@ class ContentEntityCloneBase implements EntityHandlerInterface, EntityCloneInter
    +    //Updates last-modified date of cloned entity if option is checked.
    

    Set a space after the comment slashes.

  2. +++ b/src/Form/EntityCloneForm.php
    @@ -166,6 +166,13 @@ class EntityCloneForm extends FormBase {
    +        '#title' => $this->stringTranslationManager->translate('Update "Last-Modified".'),
    

    No period sign required for the checkbox label.

  3. +++ b/src/Form/EntityCloneForm.php
    @@ -166,6 +166,13 @@ class EntityCloneForm extends FormBase {
    +        '#description' => $this->stringTranslationManager->translate('Updates "last modified" date of newly created cloned entity'),
    

    A period sign is required for the description sentence.

  4. +++ b/src/Form/EntityCloneSettingsForm.php
    @@ -118,6 +118,13 @@ class EntityCloneSettingsForm extends ConfigFormBase implements ContainerInjecti
    +      '#title' => $this->t('Updates "last-modified" date to the cloning date.'),
    

    No period sign is required for the checkbox label.

  5. +++ b/src/Form/EntityCloneSettingsForm.php
    @@ -118,6 +118,13 @@ class EntityCloneSettingsForm extends ConfigFormBase implements ContainerInjecti
    +      '#description' => $this->t('Wheter the "Update last-modified" option should be checked by default on the entity clone form.'),
    

    Typo: wheter => whether

fernly’s picture

Status: Needs review » Needs work
guilhermevp’s picture

Hi @Fernly Thanks for your Feedback! I'll work on it!

upchuk’s picture

Assigned: guilhermevp » Unassigned
Status: Needs work » Needs review
StatusFileSize
new6.82 KB

Actually, it doesn't make that much sense to make this configurable. I find it difficult to believe there is a use case where a cloned entity's update date should ever be before the created one.

Moreover, when setting the updated date, we should check if there is such a field. Luckily for this there is an interface.

I created a patch with test refactor that tests both created and updated dates for nodes.

upchuk’s picture

Assigned: Unassigned » upchuk

Following from https://www.drupal.org/project/entity_clone/issues/3266268, I need to add also handling for translations.

Upchuk credited n.ghunaim.

upchuk’s picture

Assigned: upchuk » Unassigned
Related issues: +#3266268: Curent date only applied to cloned entity, not its translation entity
StatusFileSize
new10.57 KB
new7.34 KB

Here we are, setting the created/updated dates also on the translations + minor refactor + tests.

joevagyok’s picture

Status: Needs review » Reviewed & tested by the community

Reviewed and tested the patch. Works as designed. Thank you, moving it to RTBC.

sinn’s picture

Patch #10 works well.

upchuk’s picture

StatusFileSize
new10.81 KB

Rerolling and re-running tests.

  • Upchuk committed cf354c0 on 8.x-1.x
    Issue #3216900 by Upchuk, guilhermevp, Fernly, n.ghunaim, joevagyok,...
upchuk’s picture

Status: Reviewed & tested by the community » Fixed

Merged

Status: Fixed » Closed (fixed)

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