Skip to content

[cmrf_views] Make the API for retrieving CiviCRM files configurable by field metadata

jensschuppe requested to merge viewsFileAPI into 2.1.x

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 current Attachment
  • file_api.action describing the API action, falling back to current getsingle
  • file_api.version describing the API version, falling back to current 3
  • file_api.id_param describing the API action's parameter name for the file ID, falling back to current id
  • file_api.url_param describing the API action's parameter name for the retrieved download URL, falling back to current url
  • file_api.name_param describing the API action's parameter name for the retrieved file name, falling back to current name
  • 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 the file_api.attached_entity_param parameter, not needed currently, but falling back to the entity property of the file field definition for using a join to that entity via EntityFile when the API is File.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.

Merge request reports

Loading