Problem/Motivation

Media entities are revisionable but it's not possible to:

  • view a revision
  • revert to a revision
  • delete a specific revision
  • see a diff of revisions, if the contrib Diff module is enabled.

Proposed resolution

Introduce the revisions tab, like we have it for node.

Remaining tasks

Also introduce 'view all revisions', 'revert all revisions' and 'delete all revisions' permission.

User interface changes

API changes

Data model changes

Issue fork drupal-2911977

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chr.fritsch created an issue. See original summary.

chr.fritsch’s picture

All the code for a revision ui currently lives in NodeController. So we should generalize it somehow, so it could be used for node and media.

vijaycs85’s picture

Issue tags: +Workflow Initiative
chr.fritsch’s picture

Status: Active » Closed (duplicate)
chr.fritsch’s picture

Status: Closed (duplicate) » Postponed
chr.fritsch’s picture

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

rlnorthcutt’s picture

What about using views? That would enable users to modify the revision page/table if they have extra media fields, for example.

https://gist.github.com/rlnorthcutt/dff8e7df2d6336089cd2234b0109e1a5

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

iuana’s picture

Assigned: Unassigned » iuana
pameeela’s picture

Does this issue cover everything related to viewing media revisions? The issue I'm seeking clarification on is, currently you can create a revision of a media entity and add a revision log message, but there seems to be no way to view these.

I am not looking to revert or delete revisions, just to view them. Is it accurate that there is no way to do this currently? If not can someone point me in the right direction?

iuana’s picture

Assigned: iuana » Unassigned
nareshbw’s picture

I am also facing the same issue. Please suggest a patch by which we can provide revert functionality for media same like node.

bruce.yuen’s picture

If you just want to view the revision log through a revisions tab on media without the diff module features, I've created a module just for that on my github:
Link to the media_revision_log module.

I created this module for the project I am on and it is going to production on their website. Hope it helps for those that just want to see the logs from the front-end, instead of having to check the media revision tables in the database for their customers.

bruce.yuen’s picture

If you just want to view the revision log messages from the front-end through a revisions tab on a media, then I've created a module just for that:
Link to the media_revision_log module

I created this module for the project I am on and stakeholders are deploying it into production. Hopefully this helps those that just want to view the log messages, and saves them time from looking in the database for their customers to find them.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

andrewmacpherson’s picture

This will be important when extra fields are added to audio/video media as part of the plan at #3002770: Provide authors with tools to manage transcripts and captions/subtitles for local video and audio.

In particular, transcripts will be a long text field, so the ability to manage revisions (or compare them with Diff module) will be really useful.

I wouldn't say that a revisions UI for media entities is a blocker for that plan though.

bcizej’s picture

I created a module that adds a Revisions tab for media entities.

https://www.drupal.org/project/media_revisions_ui

You can view, revert or delete revisions the same way as nodes.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

apaderno’s picture

Is this issue postponed on a different issue? If this is the case, which issue is this?
(I don't see any comment changing the status; yet, the issue passed from Closed (duplicate) to Postponed.)

phenaproxima’s picture

Category: Task » Feature request
Status: Postponed » Closed (duplicate)
Issue tags: +Triaged Media Initiative issue

I think this looks like a duplicate of #2350939: Implement a generic revision UI, which would address this generically, so I'm closing it out in favor of that.

dpi’s picture

Version: 9.1.x-dev » 10.1.x-dev
Status: Closed (duplicate) » Active

It seems appropriate to re-open this, as #2350939: Implement a generic revision UI introduces a foundation for a revision UI, but intentionally does not add it to any entity types.

#2350939: Implement a generic revision UI is now merged, unblocking this.

AaronMcHale’s picture

dpi’s picture

Title: Introduce revisions tab for media » Add Media revision UI

renaming in the same style as its peers, e.g. #1984588: Add Block Content revision UI

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

yash.rode’s picture

Assigned: Unassigned » yash.rode
Status: Active » Needs work

Trying to implement the reqested feature.

yash.rode’s picture

Implemented basic functionality, needs test coverage.

yash.rode’s picture

Wim Leers’s picture

yash.rode’s picture

It is working for Block content so I am missing something, trying to find that.

AaronMcHale’s picture

#3323788: Revert and Delete actions should not be available for the current revision doesn't actually have to block this issue.

The reason it didn't block #1984588: Add Block Content revision UI is because in that issue the logic to remove the revert and delete button was added to the block content access handler, but I created #3323788: Revert and Delete actions should not be available for the current revision because there's no reason that it can't be added to a generic access handler, since pretty much every implementation of the generic revision UI will need that same logic.

So not strictly a blocker, but it would be really nice if we could do it in the generic access handler and not have the same code duplicated for each implementation.

yash.rode’s picture

Still the access needs to be changed and test coverage for it.

yash.rode’s picture

Assigned: yash.rode » Unassigned
Status: Needs work » Needs review
Chris Matthews’s picture

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs change record

This seems in line with what we did for Block Content

Applying MR 4057 to 11.x and clearing cache I can confirm I'm seeing the revisions tab on media.
Created a few revisions and reverted back n forth with no issue.

Test coverage also seems to fully cover the change.

Only thing missing we did for Block Content is add a change record.

yash.rode’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record
larowlan’s picture

@yash the change notice shouldn't be published until the issue is merged, I've unpublished it. Thanks for creating it!

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Change record and everything else looks good to me!

Wim Leers’s picture

Status: Reviewed & tested by the community » Needs work

There appears to be one BC break for JSON:API? If we can revert the JSON:API test change and the test still passes, then my only major concern would be addressed! 😊

yash.rode’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Think the one open thread is legit. Needing those permissions for GET doesn't seem correct. The node module didn't need to grant access to the content page as a reference.

yash.rode’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

How come we are editing the current access checking? I have a feeling this could impact existing sites if not configured in a specific way.

yash.rode’s picture

Status: Needs work » Needs review

It won't cause any BC problem as there was already an early return for admin in upstream.

yash.rode’s picture

I am not sure if we want to Allow admin permission to override all operations for revisions also?

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Lets see what the committers think. Don't think I can make that call.

lauriii’s picture

Status: Reviewed & tested by the community » Needs review
yash.rode’s picture

I have a doubt about the permissions, do we need two if checks in the \Drupal\media\MediaAccessControlHandler::checkAccess()'s view all revisions case? asking this because we don't have anything like that for block content but it was there in upstream for media.

smustgrave’s picture

Will admit block content may need some tweaking itself. We just added granular permissions a few weeks ago.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Moving back to committer eyes.

larowlan’s picture

Status: Reviewed & tested by the community » Needs work

Left some comments on the MR, there's something awry with the permissions in my opinion

yash.rode’s picture

Assigned: Unassigned » yash.rode
yash.rode’s picture

Assigned: yash.rode » Unassigned
Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Still appears to be working.

phenaproxima’s picture

Status: Reviewed & tested by the community » Needs work

This seems reasonably straightforward but could use some cleanup.

yash.rode’s picture

Status: Needs work » Needs review

addressed feedbak.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Back to the committer queue.

phenaproxima’s picture

Status: Reviewed & tested by the community » Needs work

I'm sorry, this isn't quite ready to go yet. There is still some stuff that could use clean-up and consistency; in particular, I'm not sure the functional test coverage is testing all the ins and outs that it should.

Additionally, is there any testing for support of translated revisions? Do we need additional coverage for that? I'd be okay deferring that to a follow-up, since I think most if not all of Media's translation handling is bog-standard for core entities. Thoughts, @larowlan or other framework managers?

yash.rode’s picture

Assigned: Unassigned » yash.rode
phenaproxima’s picture

Shaping up! But I have more feedback. I'm not sure the functional test coverage is as robust as it should be, and it could still use some streamlining.

yash.rode’s picture

Assigned: yash.rode » Unassigned
Status: Needs work » Needs review
yash.rode’s picture

Assigned: Unassigned » yash.rode
Status: Needs review » Needs work

Got some idea about the default and latest, so giving it a shot.

phenaproxima’s picture

I discussed this today with @yash.rode and I think the thing I'm stuck on, at least for now, is: why are we borrowing access logic from Block Content?

Custom blocks are not meant to be viewed on their own. Media sort of is -- it's disabled by default, but they're not quite embedded things like blocks are. I feel like Node's access control logic is closer to what we'd want for media items, albeit without the complicated system of access grants.

To me, the logic we want is this, based on permissions:

If the operation is view, you can see the media if ANY of the following are true:

  • You have view all media revisions
  • You have view any TYPE_ID media revisions
  • You have administer media (this is already the case in HEAD)

If the operation is revert or delete revision, you can do the operation if either:

  • You have revert any TYPE_ID media revisions/delete any TYPE_ID media revisions
  • You have administer media

AND the media item in question is NOT the default revision. It's okay if it's the latest revision -- that ensures it plays nicely with Content Moderation, which has the concept of a newer, not-yet-published revision -- but you can't revert or delete the default revision, because that makes no sense. So, for example:

      case 'revert':
        return AccessResult::allowedIfHasPermissions($account, [
          'revert any ' . $type . ' media revisions',
          'administer media',
        ], 'OR')
          ->andIf($is_not_default_revision);

So, to summarize my thoughts here: I think we SHOULD prevent destructive operations on the default revision, but NOT take into account whether it is also the latest revision. That only comes into play when Content Moderation is enabled.

Now, that being said, Yash pointed out to me that, without Content Moderation, all revisions that are created are considered the default revision. I confirmed that he's correct -- the problem seems to be that \Drupal\Core\Entity\ContentEntityBase::$isDefaultRevision has a default value of TRUE, and except for Content Moderation, there is no way to override that in the UI! In other words, Drupal's default behavior is that every revision is the default revision. That seems utterly bananas to me -- and it effectively means that, if we do the thing I just laid out, you can never revert or delete a revision, because all revisions are the default!! (Unless, of course, you have Content Moderation set up for media.) So I see why Yash had to put in the logic that also checks for the latest revision.

But surely that is a bug in core? Do we have an issue to fix Drupal's behavior such that only the latest revision is the default revision, rather than all of them being the default? If not, we probably want to open that issue.

yash.rode’s picture

Assigned: yash.rode » Unassigned
Status: Needs work » Needs review

Then what about the logic that controls access to latest revision, for removing revert and delete revision button. We need that for generic revision UI.

phenaproxima’s picture

Ooof! 🤯 🤬 What a maddening bug!

IMHO the correct thing to do is postpone this issue on getting that bug fixed. Chances are, the fix isn't too complicated to implement. I'd rather we did that than add confusing workarounds to this issue.

smustgrave’s picture

Status: Needs review » Postponed

Per #68.

sumit_saini’s picture

lauriii’s picture

yash.rode’s picture

Assigned: Unassigned » yash.rode

Rebasing and changing the MediaAccessControlHandler.

Wim Leers’s picture

Posted a new review 🏓

Berdir’s picture

> Then I think it'd be better to not have both Media::preSaveRevision() and BlockContent::preSaveRevision() achieve the same behavior using two very different method implementations and instead move that to EditorialContentEntityBase::preSaveRevision() RevisionLogEntityTrait::preSaveRevision().

We have an existing issue to standardize that, but it's been stuck on semantics/naming for years. This is not the issue for this and I don't think it should block it.

Wim Leers’s picture

@Berdir: TIL!

Then let's:

  1. link that issue and have that issue point to this as another example.
  2. at least ensure that BlockContent::preSaveRevision() and Media::preSaveRevision() are identical, to allow that issue to land more easily in the future. That way, Media::preSaveRevision() needs to change only once.
Berdir’s picture

Wim Leers’s picture

yash.rode’s picture

Assigned: yash.rode » Unassigned
Status: Needs work » Needs review
yash.rode’s picture

Assigned: Unassigned » yash.rode
Status: Needs review » Needs work

Addressing Omkar's feedback.

yash.rode’s picture

Assigned: yash.rode » Unassigned
Status: Needs work » Needs review
Wim Leers’s picture

Status: Needs review » Needs work
Related issues: +#3043321: Use generic access API for node and media revision UI

AFAICT there's a security vulnerability/regression in here 😅

yash.rode’s picture

I have few questions/doubts:

  1. Do we need to add revert all revisions
and delete all revisions 
permissions like node.permissions.yml?
  2. Do we need to care about the default and latest revision in this issue? Because, we were doing that before to remove the revert and delete buttons from default revision. We don't care about revision when it's a view revision operation.
    Why to get rid of default and latest handling in this issue -> We are already doing that in #3323788: Revert and Delete actions should not be available for the current revision

Thanks in advance.

yash.rode’s picture

Status: Needs work » Needs review

Need some clarification to proceed.

smustgrave’s picture

Status: Needs review » Needs work

Should be quick fix for CC failure.

yash.rode’s picture

Status: Needs work » Needs review

Need some clarification about https://git.drupalcode.org/project/drupal/-/merge_requests/4057#note_205829.
Which test case will fail if we remove this? I can't think of any.

phenaproxima’s picture

Status: Needs review » Needs work

This is looking pretty good to me. The scope of changes is clear, and the test coverage is solid, although could use some clean-up in certain spots. But I took a long time to read all the way through this and I feel like I understand what we're trying to do.

yash.rode’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

So this one doesn't stall and maybe can land in 10.2!

Tested again by creating a Media object (Image bundle)
Editing the source file
Verified the revisions tab
Reverted back to the previous revision
Old image is used.
Deleted revision 2 jsut fine.

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

yash.rode’s picture

Addressed Ben's suggestions except one thread, which is not clear to me. Thanks for the review.

bnjmnm’s picture

Status: Reviewed & tested by the community » Needs work

Two remaining threads to address. The changes are straightforward enough that whoever makes them is welcome to self-RTBC this and get it back into committer consideration.

bnjmnm’s picture

This also needs an update hook for the entity defintion. I noticed this was added in some of the other Revision UI issues and wasn't sure why it was needed since updating the definition in the PHP class provided the expected functionality. The EntityDefinitionUpdateManagerInterface docs explain why, and there's are existing examples to work from and just swap in the media specific stuff.

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

acbramley’s picture

Status: Needs work » Needs review

Threads have been resolved, and more work has been done to fix other bugs. This needs a re-review.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Not sure I'm one that can mark this so apologize if I'm wrong

Followed the same steps as above

Tested again by creating a Media object (Image bundle)
Editing the source file
Verified the revisions tab
Reverted back to the previous revision
Old image is used.
Deleted revision 2 just fine.

Seems all the threads have been resolved except maybe the deprecation of core/modules/media/media.routing.yml. But @acbramley makes a good point about it being needed.

Think this landing in 10.2 would be great.

  • lauriii committed d4c6b321 on 11.x
    Issue #2911977 by yash.rode, acbramley, bnjmnm, smustgrave, phenaproxima...

  • lauriii committed 86c32df7 on 10.2.x
    Issue #2911977 by yash.rode, acbramley, bnjmnm, smustgrave, phenaproxima...

lauriii’s picture

Version: 11.x-dev » 10.2.x-dev
Status: Reviewed & tested by the community » Fixed
Issue tags: +10.2.0 release highlights

Committed d4c6b32 and pushed to 11.x. Also cherry-picked to 10.2.x. Thanks!

Status: Fixed » Closed (fixed)

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