[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.entitydescribing the API entity, falling back to currentAttachment -
file_api.actiondescribing the API action, falling back to currentgetsingle -
file_api.versiondescribing the API version, falling back to current3 -
file_api.id_paramdescribing the API action's parameter name for the file ID, falling back to currentid -
file_api.url_paramdescribing the API action's parameter name for the retrieved download URL, falling back to currenturl -
file_api.name_paramdescribing the API action's parameter name for the retrieved file name, falling back to currentname -
file_api.attached_entity_paramdescribing the API action's parameter name for the entity the file is attached to, not needed currently, so no fallback -
file_api.attached_entitydescribing the parameter value for thefile_api.attached_entity_paramparameter, not needed currently, but falling back to theentityproperty of the file field definition for using a join to that entity viaEntityFilewhen 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.