if ($e->mapping->getEntity() !== 'civicrm_membership') {
return;
}
-
- // FIXME: `select('e.*')` seems too broad.
+ parent::alterActionScheduleQuery($e);
$e->query
- ->select('e.*')
- ->select('mt.minimum_fee as fee, e.id as id , e.join_date, e.start_date, e.end_date, membership_type_id as Membership__membership_type_id, status_id as Membership__status_id')
+ ->select('mt.minimum_fee as ' . $this->getEntityAlias() . 'fee')
->join('mt', '!casMailingJoinType civicrm_membership_type mt ON e.membership_type_id = mt.id');
}
* @inheritDoc
*/
public function evaluateToken(\Civi\Token\TokenRow $row, $entity, $field, $prefetch = NULL) {
- $actionSearchResult = $row->context['actionSearchResult'];
-
- if (in_array($field, ['start_date', 'end_date', 'join_date'])) {
- $row->tokens($entity, $field, \CRM_Utils_Date::customFormat($actionSearchResult->$field));
- }
- elseif ($field == 'fee') {
- $row->tokens($entity, $field, \CRM_Utils_Money::formatLocaleNumericRoundedForDefaultCurrency($actionSearchResult->$field));
- }
- elseif (isset($actionSearchResult->$field)) {
- $row->tokens($entity, $field, $actionSearchResult->$field);
- }
- elseif ($cfID = \CRM_Core_BAO_CustomField::getKeyID($field)) {
- $row->customToken($entity, $cfID, $actionSearchResult->entity_id);
+ if ($field === 'fee') {
+ $row->tokens($entity, $field, \CRM_Utils_Money::formatLocaleNumericRoundedForDefaultCurrency($this->getFieldValue($row, $field)));
}
else {
parent::evaluateToken($row, $entity, $field, $prefetch);
$this->assertEquals($this->getMembershipTokens(), $tokens);
$newStyleTokens = "\n{membership.status_id:label}\n{membership.membership_type_id:label}\n";
$tokenString = $newStyleTokens . implode("\n", array_keys($this->getMembershipTokens()));
+
$memberships = CRM_Utils_Token::getMembershipTokenDetails([$this->getMembershipID()]);
$messageToken = CRM_Utils_Token::getTokens($tokenString);
$tokenHtml = CRM_Utils_Token::replaceEntityTokens('membership', $memberships[$this->getMembershipID()], $tokenString, $messageToken);
$this->assertEquals($this->getExpectedMembershipTokenOutput(), $tokenHtml);
+ // Custom fields work in the processor so test it....
+ $tokenString .= "\n{membership." . $this->getCustomFieldName('text') . '}';
// Now compare with scheduled reminder
$mut = new CiviMailUtils($this);
CRM_Utils_Time::setTime('2007-01-22 15:00:00');
'body_html' => $tokenString,
]);
$this->callAPISuccess('job', 'send_reminder', []);
- $mut->checkMailLog([$this->getExpectedMembershipTokenOutput()]);
+ $mut->checkMailLog([$this->getExpectedMembershipTokenOutput() . "\nmy field"]);
}
/**
*/
protected function getMembershipID(): int {
if (!isset($this->ids['Membership'][0])) {
- $this->ids['Membership'][0] = $this->contactMembershipCreate(
- ['contact_id' => $this->getContactID()]
- );
+ $this->ids['Membership'][0] = $this->contactMembershipCreate([
+ 'contact_id' => $this->getContactID(),
+ $this->getCustomFieldName('text') => 'my field',
+ ]);
}
return $this->ids['Membership'][0];
}