Add an option to prevent the changed date from being updated

Created on 7 June 2023, almost 2 years ago
Updated 13 September 2024, 7 months ago

Problem/Motivation

When updating various nodes, all of them will have their updated date changed to the current date which may confuse administrators to see that all content where just updated and sometimes could end up being visible on front if this field is displayed.

Steps to reproduce

Batch update several content and see the "Updated" column in /admin/content.

Proposed resolution

Add an option in the "Select fields to change" form to left the date untouched.

As a reference we have :

Remaining tasks

Patch to be written.

I don't have time right now to work on this feature, but here is a small code to help dealing with this problem.

/**
 * Implements hook_entity_presave().
 * Prevent changed date from bein update when running batches / using VBO.
 */
function MODULE_entity_presave(EntityInterface $entity) {
  if (\Drupal::routeMatch()->getRouteName() == 'system.batch_page.json' && isset($entity->original->changed)) {
    $entity->changed = $entity->original->changed;
  }
}
✨ Feature request
Status

Needs review

Version

3.0

Component

Code

Created by

πŸ‡«πŸ‡·France tostinni

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @tostinni
  • πŸ‡¦πŸ‡ΊAustralia mstrelan
  • Merge request !34Add is_syncing option β†’ (Open) created by mstrelan
  • Status changed to Needs work 7 months ago
  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    Now we have πŸ“Œ Allow ChangedItem to skip updating the entity's "changed" timestamp when synchronizing Fixed in 11.x let's focus on that as the API for this issue. I've put up an MR but it needs tests, and some way to hide it from earlier core versions.

  • Pipeline finished with Failed
    7 months ago
    Total: 395s
    #277656
  • Pipeline finished with Success
    7 months ago
    #278803
  • First commit to issue fork.
  • Status changed to Needs review 7 months ago
  • πŸ‡ΊπŸ‡¦Ukraine sickness29

    Added new test case to ViewsBulkEditActionTest to make sure new option is tested.
    Also added changes to make this option work as isSyncing is not working for Drupal 10.3

  • Pipeline finished with Success
    7 months ago
    Total: 732s
    #281264
  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    Thanks for updating this, it broke when I moved it from revision_information fieldset to a new additional fieldset.

    I'm not sure the bulk_edit_is_syncing property is a good idea, especially since dynamic properties are deprecated now. I think the best bet is a version compare and just make this compatible with newer versions. Or I suppose we could use the DeprecationHelper class.

    Attaching a patch that I'll be using on a patched 10.3 site, but hiding it so as not to derail the issue.

  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    Turns out that using is_syncing from core leads to other issues, like the current revision being set to the new draft revision instead of the existing published revision. We're going with a different approach of using a separate field for last update date and allowing the changed date to be updated when bulk editing is done.

Production build 0.71.5 2024