Answers.Body: <p>@Demerit pointed me to this <a href="https://docs.civicrm.org/dev/en/latest/framework/token/#token-processor" rel="nofollow noreferrer">https://docs.civicrm.org/dev/en/latest/framework/token/#token-processor</a></p>
  <p>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.</p>
  <p>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!</p>
  <p>So I've implemented this as well as the existing hook_civicrm_tokens and hook_civicrm_tokenValues, and it appears to work.</p>
  <p>Presumably the worst that could happen would be that both processing mechanisms were invoked and that would be okay.</p>
  <p><strong>Post script</strong> ...[2022-04-01]</p>
  <p>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.</p>
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-08T21:33:21.227Z
Answers.Text: Might also depend on version. 5.43 has some updates to token processing.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-08T22:12:52.297Z
Answers.Text: My tests are working with 5.35.2. Maybe it'll all blow up when I next upgrade CiviCRM?
Answers.UserDisplayName: Alan Dixon
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-08T20:18:17.410Z
Answers.LastActivityDate: 2022-04-01T16:19:26.503Z
Answers.LastEditDate: 2022-04-01T16:19:26.503Z
Answers.UserDisplayName: Alan Dixon
Body: <p>I have created a custom Drupal 8/9 module that defines hook_civicrm_tokens and
  hook_civicrm_tokenValues to provide tokens to CiviCRM.</p>
  <p>It works when not using mosaico, but fails (the tokens are evaluated to &quot;empty&quot;) without any noticeable error when using the same token with mosaico.</p>
  <p>Any hints on debugging this?</p>
  <p>It seemed like it could be a flexmailer issue instead and I tried the flexmailer &quot;CiviMail BAO&quot; setting instead, but that didn't seem to have any effect.</p>
  <p>I also tried upgrading to civicrm to 5.42.0, but no joy there either.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-10-14T13:22:20.613Z
Comments.Text: 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}
Comments.UserDisplayName: Aidan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-10-15T20:52:26.937Z
Comments.Text: They have a custom "namespace" (not really a namespace, but I know what you mean ...).
Comments.UserDisplayName: Alan Dixon
Tags: <civimail><tokens><mosaico><drupal-8><flexmailer>
Title: Why aren't my tokens working in mosaico?
ThreadText: # Why aren't my tokens working in mosaico?
  
  (Asked by: username_0 on 2021-10-14)
  
  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.
  
  **Tags:** civimail, tokens, mosaico, drupal-8, flexmailer
  
  > **Comments:**
  > **username_1**: 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}  
  > **username_0**: They have a custom "namespace" (not really a namespace, but I know what you mean ...).  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2021-12-08. Score: 1
  
  @username_2 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.
  
  > **Comments:**
  > **username_2**: Might also depend on version. 5.43 has some updates to token processing.  
  > **username_0**: My tests are working with 5.35.2. Maybe it'll all blow up when I next upgrade CiviCRM?  
  
  ---
  
  