4 +--------------------------------------------------------------------+
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2019 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
30 * Class CRM_Mailing_Tokens
32 * Generate "mailing.*" tokens.
34 * To activate these tokens, the TokenProcessor context must specify either
35 * "mailingId" (int) or "mailing" (CRM_Mailing_BAO_Mailing).
37 class CRM_Mailing_Tokens
extends \Civi\Token\AbstractTokenSubscriber
{
42 public function __construct() {
43 parent
::__construct('mailing', array(
44 'id' => ts('Mailing ID'),
45 'name' => ts('Mailing Name'),
46 'group' => ts('Mailing Group(s)'),
47 'subject' => ts('Mailing Subject'),
48 'viewUrl' => ts('Mailing URL (View)'),
49 'editUrl' => ts('Mailing URL (Edit)'),
50 'scheduleUrl' => ts('Mailing URL (Schedule)'),
51 'html' => ts('Mailing HTML'),
52 'approvalStatus' => ts('Mailing Approval Status'),
53 'approvalNote' => ts('Mailing Approval Note'),
54 'approveUrl' => ts('Mailing Approval URL'),
55 'creator' => ts('Mailing Creator (Name)'),
56 'creatorEmail' => ts('Mailing Creator (Email)'),
63 public function checkActive(\Civi\Token\TokenProcessor
$processor) {
64 return !empty($processor->context
['mailingId']) ||
!empty($processor->context
['mailing']);
70 * @param \Civi\Token\Event\TokenValueEvent $e
75 public function prefetch(\Civi\Token\Event\TokenValueEvent
$e) {
76 $processor = $e->getTokenProcessor();
77 $mailing = isset($processor->context
['mailing'])
78 ?
$processor->context
['mailing']
79 : CRM_Mailing_BAO_Mailing
::findById($processor->context
['mailingId']);
82 'mailing' => $mailing,
89 public function evaluateToken(\Civi\Token\TokenRow
$row, $entity, $field, $prefetch = NULL) {
90 $row->format('text/plain')->tokens($entity, $field,
91 (string) CRM_Utils_Token
::getMailingTokenReplacement($field, $prefetch['mailing']));