Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(dev/mail#83) EntityTokens - Allow using mocked data #21486

Merged
merged 2 commits into from
Sep 15, 2021

Conversation

totten
Copy link
Member

@totten totten commented Sep 15, 2021

Overview

This updates the wiring for certain token-providers ({contribution.*}, {contribution_recur.*}, etc) to follow a data-mocking pattern available to {contact.*} tokens.

This is a step toward more responsive previewing/experimentation when editing message-templates.

Before

Tokens are generally based on entity-id as input, eg

$proc->addRow([
  'contactId' => 123, 
  'contributionId' => 456, 
]);

The {contact.*} entity allows mocking or overriding specific data values, eg

$proc->addRow([
  'contactId' => 123, 
  'contact' => ['display_name' => 'Fake Name', ...],
  'contributionId' => 456, 
]);

However, this doesn't work with other entities.

After

Any entity based on CRM_Core_EntityTokens will support similar mocking/overriding, eg

$proc->addRow([
  'contactId' => 123, 
  'contact' => ['display_name' => 'Fake Name', ...],
  'contributionId' => 456, 
  'contribution' => ['net_amount' => 3211.23, 'invoice_id' => '888-999', ...],
]);

Before: EntityTokens reads `$tokenContext['contributionId']` and fetches the corresponding `civicrm_contribution`. The
data must exist in that record.

After: EntityTokens reads both `$tokenContext['contributionId']` and `$tokenContext['contribution']`. Data in
`$tokenContext['contribution']` takes precedence, rendering the content of `civicrm_contribution` mute.
@civibot
Copy link

civibot bot commented Sep 15, 2021

(Standard links)

@eileenmcnaughton
Copy link
Contributor

Looks like this is a reviewer's commit as it was originally a change I put up - so MOP on that basis + thanks for the test!

@seamuslee001 seamuslee001 merged commit 37a419f into civicrm:master Sep 15, 2021
@totten totten deleted the master-entity-mock-data branch September 15, 2021 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants