I have created a custom Drupal 8/9 module that defines hook_civicrm_tokens and hook_civicrm_tokenValues to provide tokens to CiviCRM.

It works when not using mosaico, but fails (the tokens are evaluated to "empty") without any noticeable error when using the same token with mosaico.

Any hints on debugging this?

It seemed like it could be a flexmailer issue instead and I tried the flexmailer "CiviMail BAO" setting instead, but that didn't seem to have any effect.

I also tried upgrading to civicrm to 5.42.0, but no joy there either.

  • Don't know but there have been lots of internal changes affecting tokens recently. What namespace are they in - a custom one or your own? There were some issues creating your own tokens in the standard namespaces - eg {contact.mything}
    – Aidan
    Commented Oct 14, 2021 at 13:22
  • They have a custom "namespace" (not really a namespace, but I know what you mean ...).
    – Alan Dixon
    Commented Oct 15, 2021 at 20:52

1 Answer 1


@Demerit pointed me to this https://docs.civicrm.org/dev/en/latest/framework/token/#token-processor

Aside from being new and shiny, it's using some symfony bits which Drupal also uses so it kind of feels like a nice fit.

In my initial testing, I've observed that the example code in fact only fills in the gap - i.e. the tokens don't show up in the listing, nor do they work in a traditional mailing, but they do show up in a mosaico mailing!

So I've implemented this as well as the existing hook_civicrm_tokens and hook_civicrm_tokenValues, and it appears to work.

Presumably the worst that could happen would be that both processing mechanisms were invoked and that would be okay.

Post script ...[2022-04-01]

It works in all my testing, but fails when the mailing is triggered via cv! I tried adding in --level=full, thinking that Drupal wasn't getting invoked in the same way as when doing tests, but that didn't make a difference.

To make matters worse, it seems to stop working after different kinds of upgrades, and then start working, i.e. perhaps it sometimes is working off a cache.

  • Might also depend on version. 5.43 has some updates to token processing.
    – Demerit
    Commented Dec 8, 2021 at 21:33
  • My tests are working with 5.35.2. Maybe it'll all blow up when I next upgrade CiviCRM?
    – Alan Dixon
    Commented Dec 8, 2021 at 22:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.