4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
14 * Class CRM_Mailing_Tokens
16 * Generate "mailing.*" tokens.
18 * To activate these tokens, the TokenProcessor context must specify either
19 * "mailingId" (int) or "mailing" (CRM_Mailing_BAO_Mailing).
21 class CRM_Mailing_Tokens
extends \Civi\Token\AbstractTokenSubscriber
{
26 public function __construct() {
27 parent
::__construct('mailing', [
28 'id' => ts('Mailing ID'),
29 'key' => ts('Mailing Key'),
30 'name' => ts('Mailing Name'),
31 'group' => ts('Mailing Group(s)'),
32 'subject' => ts('Mailing Subject'),
33 'viewUrl' => ts('Mailing URL (View)'),
34 'editUrl' => ts('Mailing URL (Edit)'),
35 'scheduleUrl' => ts('Mailing URL (Schedule)'),
36 'html' => ts('Mailing HTML'),
37 'approvalStatus' => ts('Mailing Approval Status'),
38 'approvalNote' => ts('Mailing Approval Note'),
39 'approveUrl' => ts('Mailing Approval URL'),
40 'creator' => ts('Mailing Creator (Name)'),
41 'creatorEmail' => ts('Mailing Creator (Email)'),
48 public function checkActive(\Civi\Token\TokenProcessor
$processor) {
49 return !empty($processor->context
['mailingId']) ||
!empty($processor->context
['mailing'])
50 ||
in_array('mailingId', $processor->context
['schema']) ||
in_array('mailing', $processor->context
['schema']);
56 * @param \Civi\Token\Event\TokenValueEvent $e
61 public function prefetch(\Civi\Token\Event\TokenValueEvent
$e) {
62 $processor = $e->getTokenProcessor();
63 $mailing = isset($processor->context
['mailing'])
64 ?
$processor->context
['mailing']
65 : CRM_Mailing_BAO_Mailing
::findById($processor->context
['mailingId']);
68 'mailing' => $mailing,
75 public function evaluateToken(\Civi\Token\TokenRow
$row, $entity, $field, $prefetch = NULL) {
76 $row->format('text/plain')->tokens($entity, $field,
77 (string) CRM_Utils_Token
::getMailingTokenReplacement($field, $prefetch['mailing']));