I've been trying to get to grips with this code and this addresses 2 things I found very confusing - notably
- using activityId when we were referring to a fieldname - we use a combination of & for
variables but normally when it's closely related to a query we use activity_id
- the function name getEntityContextSchema() was unclear to me - I concluded that in fact we were retrieving
the nname of the field for the entity ID
$tp->addMessage('body_html', $html_message, 'text/html');
foreach ($activityIds as $activityId) {
- $tp->addRow()->context('activityId', $activityId);
+ $tp->addRow()->context('activity_id', $activityId);
}
$tp->evaluate();
return new TokenProcessor(\Civi::dispatcher(), [
'controller' => get_class(),
'smarty' => FALSE,
- 'schema' => ['activityId'],
+ 'schema' => ['activity_id'],
]);
}
}
/**
+ * Get the name of the field which holds the ID of the given entity.
+ *
* @return string
*/
- private function getEntityContextSchema(): string {
- return 'activityId';
+ private function getEntityIDFieldName(): string {
+ return 'activity_id';
}
/**
// Find all the entity IDs
$entityIds
= $e->getTokenProcessor()->getContextValues('actionSearchResult', 'entityID')
- + $e->getTokenProcessor()->getContextValues($this->getEntityContextSchema());
+ + $e->getTokenProcessor()->getContextValues($this->getEntityIDFieldName());
if (!$entityIds) {
return NULL;
/**
* @inheritDoc
+ *
+ * @throws \CRM_Core_Exception
*/
public function evaluateToken(\Civi\Token\TokenRow $row, $entity, $field, $prefetch = NULL) {
// maps token name to api field
];
// Get ActivityID either from actionSearchResult (for scheduled reminders) if exists
- $activityId = $row->context['actionSearchResult']->entityID ?? $row->context[$this->getEntityContextSchema()];
+ $activityId = $row->context['actionSearchResult']->entityID ?? $row->context[$this->getEntityIDFieldName()];
$activity = (object) $prefetch['activity'][$activityId];
* @inheritDoc
*/
public function checkActive(\Civi\Token\TokenProcessor $processor) {
- return in_array($this->getEntityContextSchema(), $processor->context['schema']) ||
+ return in_array($this->getEntityIDFieldName(), $processor->context['schema'], TRUE) ||
(!empty($processor->context['actionMapping'])
&& $processor->context['actionMapping']->getEntity() === $this->getEntityTableName());
}
/**
* Find the fields that we need to get to construct the tokens requested.
+ *
* @param array $tokens list of tokens
* @return array list of fields needed to generate those tokens
*/
* - schema: array, a list of fields that will be provided for each row.
* This is automatically populated with any general context
* keys, but you may need to add extra keys for token-row data.
- * ex: ['contactId', 'activityId'].
+ * ex: ['contactId', 'activity_id']. (Note we are standardising on the latter).
*/
public $context;