twomice / com.joineryhq.reltoken

CiviCRM extension: Provides tokens for any related contact, for all available contact tokens. E.g., to get the spouse's first name, or parent's marriage date.
Other
1 stars 5 forks source link

handle both Activity Email and CiviMail-style token arrays #9

Closed MegaphoneJon closed 5 years ago

MegaphoneJon commented 5 years ago

At first I thought this was a bug in your extension - but it's really a bug in core. Given how long the bug has been in core (2016) I think it makes sense to account for it in the extension - especially since this fix won't need changing if the bug ever IS fixed.

Chris Burgess outlines the issue perfectly in CRM-19758 - essentially, the array passed to this hook as $tokens isn't always in the same format. As a result, the tokens this extension generates fail on CiviMail (but not quick email, scheduled reminders, etc.)

This adds a helper function (stolen from Chris Burgess) to account for both array formats.

To test: Create a template with this text:

Hi {contact.display_name},

Your employee's name is {related.display_name___reltype_b_Employee_of_Employer_of}
twomice commented 5 years ago

Merged, thanks @MegaphoneJon . I've actually hit that bug before in other contexts; should have thought about it here.