Skip to content

location tokens should return primary location type

JonGold requested to merge JonGold/emailapi:primary-location-tokens into master

Using location tokens with the Email API extension is non-deterministic; e.g. using the {contact.street_address} when the contact has multiple addresses will return one semi-randomly. We should always return the primary address/email/phone.

My change adds the default values for all the arguments to CRM_Contact_BAO_Query::apiQuery() except the last, which is $primaryLocationOnly. CRM_Contact_BAO_Query::apiQuery() generates a SQL query, then returns the results of that query. On my test contact, I had 4 phone numbers, 4 emails, and 5 addresses - the query returns 80 (445) results, except it's limited to the first 25. It then returns the 25th result. So e.g. adding a phone number can change the address returned.

This patch is both more performant (we only go once through the while loop) and will always return the primary location types.

Merge request reports

Loading