Problem/Motivation
For sites using the Trash module, if a source entity (like a node referencing a media item) is deleted, then the target entity (media, in this case) will no longer show usage from that source.
I think that's a reasonable behavior, though it could be a bit misleading because the source entity isn't truly deleted yet. Note that the entity_usage table still has the usages tracked in it, but you can't see them in the UI because Trash is hiding that the trashed node even exists.
An alternative approach would be if this module detected if the Trash module was enabled, then it could deactivate trash's hiding feature on the usage page to it continues to show that usage, but then also indicates that the source entity is in the trash. All of that adds a pretty big coupling to the Trash module though.
In any case, I think this should be documented somewhere?
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork entity_usage-3526090
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
Comment #2
marcoscanoOuch, thanks for raising this. It's indeed very unfortunate that the Trash module is so aggressive when hiding trashed entities... This means that our code in the controller:
will just think the source entity is broken since it can't be loaded, and skip it entirely from the table. I actually think this behavior from the Trash module could produce other unintended effects on sites using that module, because "the entity was moved into the trash" doesn't necessarily mean IMO "no other piece of code should be able to load this entity".
I'd like to give this a little more thought, but at this point I'm leaning towards just displaying a general warning message at the top of the usage page if the Trash module is enabled, or something along those lines. Thoughts?
Comment #3
marcoscanoI looked a bit deeper and I see that there seems to be a way to execute code bypassing Trash's hiding mechanisms. I don't really love the idea of special-casing Trash's behavior in our controller, but at this point maybe it's a good compromise?
So instead of having:
we could have something along the lines of (untested):
and similarly to other places we may be checking things on the source entities (for example access checks, getting the labels, etc). If we know the entity is in trash, we may even add a suffix of type " (in trash)" to the label...
Thoughts?
Comment #4
marcoscano@bkosborne sorry just re-read the issue summary and I am realizing you had already suggested something along those lines...
So yes I believe we should go this route, even though I think it's suboptimal from a maintenance perspective... 🤷♂️
Comment #5
marcoscanoComment #6
bkosborneOkay, I'll work on this. I also polled some coworkers about this and they all agreed that it makes sense to show the trashed sources and to indicate they are in the trash.
Comment #8
bkosborneOkay, test is failing because I was working with this patch for Trash #3526839: Trash's hook_entity_access should account for the 'view label' operation. Without that patch, trashed entities always show with a "- Restricted access -" label, even if the user has access to view trashed entities. It's a super simple fix there, so hopefully I can push that one through. But I'll postpone this issue on that.
Note there's also some phpcs failure but I don't think it's related to these changes.
Comment #9
bkosborneComment #10
bkosborneOkay, the blocker from Trash is in. Just need to wait for its next release, then these tests should pas.
Comment #11
bkosborneOkay, trash module released 3.0.17 which includes my fix. So I think our tests here should pass now. I'll re-run them.
Comment #12
daddison commentedI tested the MR on a site using trash module 3.0.21 and entity_usage 8.x-2.0-beta24. Works and marking RTBC.
Comment #13
marcoscanoI have rerolled with -dev and all tests are indeed green.
Thanks everyone for working on this!
Comment #15
daddison commentedHi maintainers! I appreciate the work you do on this useful module. Please cut a new release incorporating the trash module integration asap. Thanks!
Comment #16
marcoscano@daddison thanks for reaching out. I plan to tag a new release later this week 👍
Comment #17
daddison commentedHi @marcoscano - Are you still planning to tag a new release soon?
Comment #18
marcoscanoJust tagged https://www.drupal.org/project/entity_usage/releases/8.x-2.0-beta25 with this fix.
I was hopeful we could include other improvements in the same tag, but they are not ready yet. No big deal, I'll cut another release when that happens.
Thanks for your patience.