[cmrf_views] Make the API for retrieving CiviCRM files configurable by field metadata
This adds the possibility for file fields (which used to retrieve the download URL via the APIv3 Attachment.getsingle
action) to define the API to use for retrieving that information.
We had a scenario when Attachment.get
would fail due to exceeding the JOIN limit of the DBMS (due to a very high number of contact reference custom fields on the entity the file field is attached to) and APIv3 not really being maintained anymore to fix that.
We then tried to use APIv4 File.get
, but retrieving a download URL relies on a valid join via EntityFile
, which does not support files in custom fields, but only "core" attachments.
It turned out we needed our own API, as fixing EntityFile
in Core for retrieving files in custom fields is quite a task (involving ACLs etc.), see this Core issue for more on that.
Anyway, this MR allows defining file API metadata in the field definition for CiviMRF Views Datasets:
-
file_api.entity
describing the API entity, falling back to currentAttachment
-
file_api.action
describing the API action, falling back to currentgetsingle
-
file_api.version
describing the API version, falling back to current3
-
file_api.id_param
describing the API action's parameter name for the file ID, falling back to currentid
-
file_api.url_param
describing the API action's parameter name for the retrieved download URL, falling back to currenturl
-
file_api.name_param
describing the API action's parameter name for the retrieved file name, falling back to currentname
-
file_api.attached_entity_param
describing the API action's parameter name for the entity the file is attached to, not needed currently, so no fallback -
file_api.attached_entity
describing the parameter value for thefile_api.attached_entity_param
parameter, not needed currently, but falling back to theentity
property of the file field definition for using a join to that entity viaEntityFile
when the API isFile.get
If the API is File.get
and the version 4
, the bridge join on EntityFile
is automatically added, so that "core" attachments are supported. Maybe the API to use (Attachment.getsingle
or File.get
) could me made configurable in the Views field instance.