Automatically set revision user/log information/created time on entity revisions

Created on 12 April 2017, about 7 years ago
Updated 4 February 2024, 5 months ago

Problem/Motivation

Currently, setting revision user, revision log message, and revision creation time on a new revision is a manual process for every entity type. In Core we have individual implementations for Block Content, Media, and Node. All 3 do things slightly differently. Contrib then has to repeat this process for any entity type that supports revisions and these fields (usually when an entity type implements RevisionLogInterface

Proposed resolution

This can be done generically in entity base classes (ContentEntityBase and EditorialContentEntityBase).

Set revision user, revision creation time, and revision log message based on an entity implementing RevisionLogInterface automatically

Remaining tasks

Framework manager signoff for using user module code in the Core namespace. See #68
Refactor code in EditorialContentEntityBase to use RevisionLogInterface if possible.

User interface changes

None

API changes

Deprecating getRequestTime in Media entity.

Data model changes

None.

📌 Task
Status

Needs work

Version

11.0 🔥

Component
Entity 

Last updated 12 minutes ago

Created by

🇩🇪Germany dawehner

Live updates comments and jobs are added and updated live.
  • Needs framework manager review

    It is used to alert the framework manager core committer(s) that an issue significantly impacts (or has the potential to impact) multiple subsystems or represents a significant change or addition in architecture or public APIs, and their signoff is needed (see the governance policy draft for more information). If an issue significantly impacts only one subsystem, use Needs subsystem maintainer review instead, and make sure the issue component is set to the correct subsystem.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇦🇺Australia acbramley

    Fixes #63, the interdiff is pretty scuffed since #57 applied with quite a bit of fuzz. I'm not sure if more work needs to be done to decouple stuff as per #32?

  • 🇨🇭Switzerland Berdir Switzerland

    I've already discussed #32 with @plach then and still think that Drupal\Core doesn't have to be free of Drupal\user references, would be nice, but Drupal\user is a required module and the difference between a Drupal\Core component and a required module like user and system is IMHO minor and mostly historical/due limitations what exactly Drupal\Core components can contain.

    I can see that other parts of that comment have been addressed, the logic was moved to EditorialContentEntityBase. That said, wouldn't RevisionLogEntityTrait be a better fit for this logic? EditorialContentEntityBase is just a handy aggregation of several traits and currently doesn't have its own logic.

  • Status changed to Needs work about 1 year ago
  • 🇺🇸United States smustgrave

    Wonder if this could still get an issue summary update please per #32

  • 🇫🇮Finland lauriii Finland

    Definitely agree that we shouldn't be referencing module code from Drupal\Core and it's a policy that has been documented in https://git.drupalcode.org/project/drupal/blob/HEAD/core/lib/Drupal/Core.... However, I think it would be fair to ask for an exception from the framework managers based on the fact that there are several pre-existing uses of the same interface in the Drupal\Core namespace. We could open a follow-up for implementing a solution for #41. It doesn't look like implementing that becomes any harder if we fix this issue separately first.

  • 🇬🇧United Kingdom AaronMcHale Edinburgh, Scotland

    Could we move Drupal\user\EntityOwnerInterface to Drupal\Core\Entity\EntityOwnerInterface, and then have it use Drupal\Core\Session\AccountInterface rather than Drupal\user\UserInterface?

    Technically it might still work, as AccountInterface has an id() method and UserInterface extends AccountInterface so it wouldn't be far removed from the current implementation.

    Doing that would allow us to decouple from the user module.

  • 🇨🇭Switzerland Berdir Switzerland

    > Could we move Drupal\user\EntityOwnerInterface to Drupal\Core\Entity\EntityOwnerInterface, and then have it use Drupal\Core\Session\AccountInterface rather than Drupal\user\UserInterface?

    An "account" is currently an abstract concept that might or might not be a user entity, in theory it could be something else. Yes, UserInterface extends AccountInterface, but that means that a user is an account, not necessarily the opposite. Of course, most places we assume it is and every User::load($currentUser->id()) would fall apart badly if it weren't, but technically, that is how it is defined. So we'd first need to redefine that an account id does in fact need need to be a user id. At that point, having two different interfaces wouldn't actually make too much sense anymore.

    We'd also definitely need to to 📌 Load user entity in Cookie AuthenticationProvider instead of using manual queries Needs work as well.

    So that would have pretty big implications, and would set us back at least one major release cycle before we could rely on that.

  • 🇬🇧United Kingdom AaronMcHale Edinburgh, Scotland

    Of course, most places we assume it is and every User::load($currentUser->id()) would fall apart badly if it weren't, but technically, that is how it is defined. So we'd first need to redefine that an account id does in fact need need to be a user id.

    I was thinking about that in the back of my head, but I was also thinking that, but in theory a site could have its own "user" implementation which extends AccountInterface, and in theory not even use the user module. Again, this is just a theory, I've never practically tested that, and it's very likely that it just wouldn't work, but in theory we could support that scenario by purposefully not coupling to the user module.

  • First commit to issue fork.
  • 🇦🇺Australia mstrelan

    Re-rolled #64 for 11.x and converted to MR. Hiding patches. Have not addressed any recent comments.

  • Pipeline finished with Success
    7 months ago
    #59219
  • First commit to issue fork.
  • 🇮🇳India ankithashetty Karnataka, India

    Updated version to 10.2.0.
    Thanks!

  • Pipeline finished with Failed
    7 months ago
    Total: 629s
    #59337
  • First commit to issue fork.
  • 🇦🇺Australia acbramley

    Pushed an updated 11.x branch to the fork to fix the spellcheck error, see https://www.drupal.org/project/drupal/issues/3401988#comment-15400828 🐛 Spell-checking job fails with "Argument list too long" when too many files are changed Active

  • 🇦🇺Australia acbramley

    acbramley changed the visibility of the branch 11.x to hidden.

  • Pipeline finished with Success
    6 months ago
    Total: 11053s
    #78474
  • Status changed to Needs review 6 months ago
  • 🇦🇺Australia acbramley

    Updated IS, added framework manager tag based on #68. FWIW - I really hope we can use the interface there because the magic getters/setters are not great in the current state.

  • 🇩🇪Germany Tomefa Dresden

    Trying the patch for Drupal 10 in comment #64 and when creating a new media, the revision user is now correctly set.

    But when editing the same media with another user, the revision is still set to the owner user id and not the user that is editing the media.

    In media_form_alter, i have to manually set it to finally have the current user in the revision log.

      $media_entity = $form_state->getFormObject()->getEntity();
      $media_entity->setRevisionUserId(\Drupal::currentUser()->id());
    
  • Status changed to Needs work 5 months ago
  • 🇦🇺Australia acbramley

    NW based on #81 - great find @Tomefa

    The weird part is, that code looks to have come from Node (setting the revision author to the author if it's not set) so I wonder why that same issue doesn't already apply to Node.

    Will try to dig into it today.

    Marking as Needs tests to cover that scenario (editing with a different user)

  • 🇦🇺Australia acbramley

    To answer #82 - it comes from here https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co...

    Manually testing Media works fine for me.

    However, it doesn't make sense to set the revision author in 2 places, and it especially doesn't make sense to set it to the author. I think we should remove it from the form and fix the entity base implementation.

  • 🇦🇺Australia acbramley

    Pushed test coverage for #81, still unsure how to reproduce it via the UI since Media goes through that same form base.

    The !$this->getRevisionUser() check in ContentEntityBase also fails on API based updates so we may need to remove that and always hardset to the current user.

  • Pipeline finished with Failed
    5 months ago
    Total: 524s
    #87565
  • Pipeline finished with Failed
    5 months ago
    Total: 616s
    #87575
  • Pipeline finished with Failed
    4 months ago
    Total: 566s
    #101023
  • Pipeline finished with Failed
    4 months ago
    Total: 187s
    #101075
  • Pipeline finished with Failed
    4 months ago
    Total: 516s
    #101079
Production build 0.69.0 2024