Answers.Body: <p>Welcome to CiviCRM Stackexchange.</p>
  <p>You can use the below code in your tokenvalue or token processor hook for contribution receipts.</p>
  <pre><code>$contributionID = CRM_Core_Smarty::singleton()-&gt;get_template_vars('contributionID');
  </code></pre>
  <blockquote>
  <p>Note: To call tokenvalue hook from your extension, the extension needs
  to have tokens present in the extension.</p>
  </blockquote>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-22T14:46:28.453Z
Answers.Text: This seems to work for the deprecated hook_civicrm_TokenValues.
  Are you sure it can also work in the TokenProcessor event?
  
  Legacy hook will continue to work for some time I expect, but it would be great to future-proof this customization.
Answers.UserDisplayName: ginkgoMZD
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-22T21:28:03.440Z
Answers.Text: Yes it should also work in tokenprocessor as well
Answers.UserDisplayName: Pradeep Nayak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-21T23:53:15.757Z
Answers.LastActivityDate: 2022-03-21T23:53:15.757Z
Answers.UserDisplayName: Pradeep Nayak
Answers.Body: <p>After trial and error and consulting the source: here is how we retrieved the Contribution ID from the TokenProcessor Context:</p>
  <pre><code>function handle_evaluate_tokens(\Civi\Token\Event\TokenValueEvent $e) {
    $tp = $e-&gt;getTokenProcessor();
    $context_contrib = $tp-&gt;getContextValues('contributionId');
    $contribution_id = array_pop($context_contrib); // unbox;
  ...
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-25T21:40:19.263Z
Answers.LastActivityDate: 2022-03-25T21:40:19.263Z
Answers.UserDisplayName: ginkgoMZD
Body: <p>We want to customize our System Workflow Messages for Contribution Receipts using custom tokens. The tokens need to retrieve an id from a custom field on the Contribution. Using either the <code>hook_civicrm_tokenValues()</code> or the new Token Processor events, do not provide us with the Contribution ID.</p>
  <p>Is there a trick to using the Token Processor approach, or do we need to use overrides to alter how Core is dispatching the token events?</p>
  <p>Thank You!</p>
  
Tags: <wordpress>
Title: We want to customize our System Workflow Messages for Contribution Receipts
ThreadText: # We want to customize our System Workflow Messages for Contribution Receipts
  
  (Asked by: username_0 on 2022-03-21)
  
  We want to customize our System Workflow Messages for Contribution Receipts using custom tokens. The tokens need to retrieve an id from a custom field on the Contribution. Using either the `hook_civicrm_tokenValues()` or the new Token Processor events, do not provide us with the Contribution ID.
  
  Is there a trick to using the Token Processor approach, or do we need to use overrides to alter how Core is dispatching the token events?
  
  Thank You!
  
  **Tags:** wordpress
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2022-03-21. Score: 1
  
  Welcome to CiviCRM Stackexchange.
  
  You can use the below code in your tokenvalue or token processor hook for contribution receipts.
  
  ```
  $contributionID = CRM_Core_Smarty::singleton()->get_template_vars('contributionID');
  
  ```
  
  > Note: To call tokenvalue hook from your extension, the extension needs
  > to have tokens present in the extension.
  
  > **Comments:**
  > **username_2**: This seems to work for the deprecated hook_civicrm_TokenValues. Are you sure it can also work in the TokenProcessor event?  Legacy hook will continue to work for some time I expect, but it would be great to future-proof this customization.  
  > **username_1**: Yes it should also work in tokenprocessor as well  
  
  ---
  
  ### Answer by username_2 on 2022-03-25. Score: 0
  
  After trial and error and consulting the source: here is how we retrieved the Contribution ID from the TokenProcessor Context:
  
  ```
  function handle_evaluate_tokens(\Civi\Token\Event\TokenValueEvent $e) {
    $tp = $e->getTokenProcessor();
    $context_contrib = $tp->getContextValues('contributionId');
    $contribution_id = array_pop($context_contrib); // unbox;
  ...
  }
  
  ```
  
  
  ---
  
  