Resolving disclosures for files¶
ai_disclosure.resolver starts from an entity. Media work often starts from a
file: an image effect has only the source URI, a transcoding job has a file
ID, an editor image has no field at all. Ask ai_disclosure.file_resolver:
$resolver = \Drupal::service('ai_disclosure.file_resolver');
$resolved = $resolver->forFile($file);
$resolved = $resolver->forUri('public://photos/team.jpg');
Both return the same ResolvedDisclosure as the entity
resolver, or NULL when nothing applies.
The rules¶
The service reads core's file usage, loads the entities that use the file and
resolves each one with ai_disclosure.resolver.
- A media entity whose bundle has an
ai_disclosurefield decides. When one does, entities that use the file directly are not consulted, even if a media entity resolves to NULL: "no disclosure" on the media is an answer. - Without such a media entity, the entities that use the file directly decide: an image field on a node, for instance.
- When several entities apply, the highest grade severity wins, so a file is never under-labelled. This includes every translation of an entity: the file is shared by all of them, and file usage does not say which one is being shown.
- A file nobody uses, or whose users have no disclosure field, resolves to NULL.
Host entities do not pass anything down¶
The disclosure of an entity that only references a media entity does not
flow down to the media. A node graded ai_summarized says nothing about the
photos embedded in it, and such a node does not use the file directly, so it
is not consulted. The reverse direction is the formatter's business: it
shows a media entity's disclosure on the page that embeds it.
Cacheability¶
forFileWithCacheability() and forUriWithCacheability() return
['resolved' => ?ResolvedDisclosure, 'cacheability' => CacheableMetadata], like
resolveWithCacheability(). The cacheability covers the file, every entity
consulted and each of their resolutions, and is there on a NULL result too.
An unknown URI carries the file_list cache tag.
Results are memoized per request, keyed on the file ID. Call resetMemo() if
the files' users change within the request.
Without the file module¶
The file module is not a dependency of ai_disclosure. Without it every file
resolves to NULL.