Add support for File entities and full Views integration

Created on 13 October 2022, about 2 years ago
Updated 15 March 2024, 9 months ago

Problem/Motivation

The current file_usage counter implementation in Drupal core is a little limited since it doesn't provide the ability to track the file usage in a consistent manner e.g. by specific revisions, or provide an API for rebuilding the usage count itself for contrib modules which reference files in a different way e.g. inside non-standard formats like JSON objects like:

With the aim being to provide a similar behaviour to the existing /admin/content/files/usage/{fid} view, it also makes sense to improve Views integration as part of this issue in particular:

  1. Adding the ability to interact with all the entity_usage database fields.
  2. Supporting revisions - #3125347: Allow revision based views to use the existing Entity Usage views field.
  3. Supporting viewing entity_usage based on the sources (if so desired) - #3138083: Add views relation for source entity
  4. Introducing views plugins to provide feature parity with the current ListUsageController - #3138083: Add views relation for source entity

With the advantage being that the entity usage lists can be easily customized to suit different use cases, while leveraging most of Views' perfomant/caching capabilities (see 🐛 Entity usage list does not scale Needs review ).

Steps to reproduce

The module explicitly disables support for file and user entities at the moment presumably because it doesn't provide a canonical by default.

Proposed resolution

Add special handling for File entities just as we do for Paragraphs.

Add views integration providing the ability to replicate the existing controller view (and can be used to replace core's existing /admin/content/files/usage/{fid} view).

Remaining tasks

Provide issue fork.

User interface changes

Form settings will include a new option to determine if the entity should include the "Entity usage" link as an operation.

This is useful for entities such as File which might not have a standalone canonical but still want to support entity usage tracking.

API changes

TBD.

Data model changes

N/A.

📌 Task
Status

Needs work

Version

2.0

Component

Code

Created by

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

Comments & Activities

Not all content is available!

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

Production build 0.71.5 2024