Skip to content

resolve hook tokens last to handle conflict with core tokens

JonGold requested to merge JonGold/pdfapi:later-hook-tokens into master

Steps to replicate

  • Install CiviToken, and turn on at least one contribution token.
  • Create a template with a core contribution token (e.g. {contribution.total_amount}.)
  • Create a CiviRule that uses PDF API to generate a PDF based on a contribution, using this template.

Expected Result {contribution.total_amount} resolves correctly.

Actual Result {contribution.total_amount} resolves as NULL.

The issue is that these lines pull a list of token categories from all the extensions. Later, the category list is used to determine which token categories to replace via hook.

That's fine if your categories are unique - e.g. {jontoken.middle_initial}. However, if you use categories that overlap with core token categories (e.g. contact.middle_initial or contribution.middle_initial), those tokens are overwritten with NULL.

I don't think the fault really lies in PDF API - this feels like a failing of core, or of extension authors using core categories for tokens. However, CiviToken uses contribution as a category for many of its tokens. Since changing CiviToken would break everyone's templates, I'm submitting this PDF, which moves resolution of hook-based tokens (back) to the end of the token resolution list.

Merge request reports