Skip to content
Snippets Groups Projects

switch to token processor

Merged david requested to merge (removed):switch-to-token-processor into master
2 unresolved threads

This switchs pdf->create and pdf->sendPdf to use the new TokenProcessor. The idea was copied from the change from email api emailapi!43 (merged)

I have tested together with civicrm 5.43 / 5.54 and CiviRules. We use this Tokens: contact (core and custom), event (core and custom), participiant (core and custom).

Not tested: Case and Contribution Tokens and Multiply contacts

Edited by david

Merge request reports

Merged by jaapjansmajaapjansma 2 years ago (Feb 23, 2023 10:25am UTC)

Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
115
116 if (isset($this->_apiParams['case_id']) && !empty($this->_apiParams['case_id'])) {
117 $schema[] = 'caseId';
118 $context['caseId'] = $this->_apiParams['case_id'];
119
120 //CRM-4524
121 // Hack for Case Token Extension
122 \Civi::$statics['casetokens']['case_id'] = $this->_apiParams['case_id'];
123 }
124 elseif (isset($this->_apiParams['extra_data']['case']) && !empty($this->_apiParams['extra_data']['case'])) {
125 $schema[] = 'caseId';
126 $context['caseId'] = $this->_apiParams['extra_data']['case']['id'];
116 127 }
117 128
118 $html = [];
129 foreach ($this->_apiParams['extra_data'] as $entity => $entityData) {
  • The first change is that the collection of data and extra_data is moved to the beginning and then I try in a loop to load all extra_data (function copied from mail api). So now event and subscriber data are also loaded, that was the reason for me to switch to the token processor.

  • Please register or sign in to reply
  • 135 'sort_name' => 1,
    136 'email' => 1,
    137 'address' => 1,
    138 'do_not_email' => 1,
    139 'is_deceased' => 1,
    140 'on_hold' => 1,
    141 'display_name' => 1,
    142 ];
    143 if (is_array($messageTokens['contact'])) {
    144 foreach ($messageTokens['contact'] as $prop) {
    145 $returnProperties[$prop] = 1;
    151 $this->_htmlMessage = $this->formatMessage($messageTemplate);
    152
    153 $filterdIds = [];
    154 // search for contacts which should not resive a mail
    155 $filterdContacts = \Civi\Api4\Contact::get()
    • I think this is the biggest change. Here the logic is reversed. Old: first get all token values and then check if it is a valid mail. New: get invalid mail and then get token values.

      I am not trying (and don't know) if it is possible to use the token processor first and then sort so the logic would be the same.

    • Please register or sign in to reply
  • @justinfreeman I add some comments and hope this is helpful.

  • Awesome thanks @david124136468769 for taking the time to explain those changes.

    PR works for us.

    @jaapjansma review required mate.

  • This patch will be tested by someone from CiviService. After they have tested it I will merge it and create a new release.

    @justinfreeman do you have anything particular you want me to review?

  • jaapjansma mentioned in commit 508fe2ff

    mentioned in commit 508fe2ff

  • merged

  • I have merged this for now and I will test this a bit futher and fix follow up issues. Thanks for the fix!

  • Please register or sign in to reply
    Loading