Allow to optionally track hotlinks to file URLs through the Entity Usage module

Issue information

From user: marcoscano

Contribution record

Fork management

Problem/Motivation

Unless developers do some cautious work to remove from the UI all references the file URLs, there is always the possibility that editors create links in WYSIWYG areas hotlinking directly to the files. In those cases, core's usage tracking doesn't account for these links.

The Entity Usage modules is able to track these links, if configured to do so. Would it make sense to consider both usage counts, if the module is installed?

Steps to reproduce

Without the patch:

* Create an image or file media item by uploading a file to it.
* Copy the direct URL to the file (for example sites/default/files/2021-07/foo.jpg )
* Create a node with a WYSIWYG field, and create a link in the text area pointing to the URL you copied above
* Click to delete the media item
* Expected: The delete confirmation page should not offer to delete the file, since this would cause a broken link on the node
* Actual: The delete form allows to also delete the referenced file.

With the patch:

* Install Entity Usage, configure it to allow "File" entities as target at `/admin/config/entity-usage/settings`, and make sure the "HTML Links" tracking plugin is enabled. If you want to allow absolute URLs, add the domain to the corresponding list as well.
* Repeat the steps from above
* Verify the confirmation form no longer offers to delete the referenced file.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Edited by drupalbot
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information