Resolve a disclosure for a file from the entities that use it
Problem/motivation
DisclosureResolver::resolve() starts from an entity. Media work starts from a file: an image effect only gets the source URI, an FFmpeg job gets a file ID, and an image inserted in CKEditor has no field at all. There is no way back from a file to its disclosure.
Proposed resolution
A service ai_disclosure.file_resolver with:
forFile(FileInterface $file): ?ResolvedDisclosureforUri(string $uri): ?ResolvedDisclosure, for callers that only have a URI.
It looks up file usage, loads the entities that use the file and resolves each with DisclosureResolver:
- The media entity that owns the file decides, when its bundle has a disclosure field.
- Without one, fall back to the entities that use the file directly, such as an image field on a node.
- When several entities apply, take the highest severity, so a file is never under-labelled.
- Return NULL when nothing applies.
Results are memoised per request and carry the cacheability of every entity consulted.
Open question: should the disclosure of a host entity ever flow down to the media it references? A node graded ai_summarized says nothing about its photos, so the proposal is no.
Remaining tasks
- Service, interface and services.yml entry
- Kernel tests: a file on one media entity, a file used by two entities with different grades, an unused file
- Page under
docs/developers/
User interface changes
None.
API changes
New service ai_disclosure.file_resolver.
Data model changes
None.
Part of #56 (closed).
Edited by Giorgio Alfredo Pagano