Merge pull request #15942 from seamuslee001/contact_fields_metadata
[civicrm-core.git] / CRM / Activity / Tokens.php
index 8730ada82b3d3a9120a15af367e6cd8a83475c01..21f6300f608c7c64f8d4eb1c274f3ce0f3ef0a4e 100644 (file)
@@ -2,33 +2,17 @@
 
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 5                                                  |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2019                                |
- +--------------------------------------------------------------------+
- | This file is a part of CiviCRM.                                    |
- |                                                                    |
- | CiviCRM is free software; you can copy, modify, and distribute it  |
- | under the terms of the GNU Affero General Public License           |
- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ | Copyright CiviCRM LLC. All rights reserved.                        |
  |                                                                    |
- | CiviCRM is distributed in the hope that it will be useful, but     |
- | WITHOUT ANY WARRANTY; without even the implied warranty of         |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
- | See the GNU Affero General Public License for more details.        |
- |                                                                    |
- | You should have received a copy of the GNU Affero General Public   |
- | License and the CiviCRM Licensing Exception along                  |
- | with this program; if not, contact CiviCRM LLC                     |
- | at info[AT]civicrm[DOT]org. If you have questions about the        |
- | GNU Affero General Public License or the licensing of CiviCRM,     |
- | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ | This work is published under the GNU AGPLv3 license with some      |
+ | permitted exceptions and without any warranty. For full license    |
+ | and copyright information, see https://civicrm.org/licensing       |
  +--------------------------------------------------------------------+
  */
 
 /**
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2019
+ * @copyright CiviCRM LLC https://civicrm.org/licensing
  */
 
 /**
@@ -50,14 +34,8 @@ class CRM_Activity_Tokens extends \Civi\Token\AbstractTokenSubscriber {
    */
   public function __construct() {
     parent::__construct('activity', array_merge(
-      array(
-        'activity_id' => ts('Activity ID'),
-        'activity_type' => ts('Activity Type'),
-        'subject' => ts('Activity Subject'),
-        'details' => ts('Activity Details'),
-        'activity_date_time' => ts('Activity Date-Time'),
-      ),
-      CRM_Utils_Token::getCustomFieldTokens('Activity')
+      $this->getBasicTokens(),
+      $this->getCustomFieldTokens()
     ));
   }
 
@@ -66,8 +44,7 @@ class CRM_Activity_Tokens extends \Civi\Token\AbstractTokenSubscriber {
    */
   public function checkActive(\Civi\Token\TokenProcessor $processor) {
     // Extracted from scheduled-reminders code. See the class description.
-    return
-      !empty($processor->context['actionMapping'])
+    return !empty($processor->context['actionMapping'])
       && $processor->context['actionMapping']->getEntity() === 'civicrm_activity';
   }
 
@@ -84,7 +61,8 @@ class CRM_Activity_Tokens extends \Civi\Token\AbstractTokenSubscriber {
     // Q: Could we simplify & move the extra AND clauses into `where(...)`?
     $e->query->param('casEntityJoinExpr', 'e.id = reminder.entity_id AND e.is_current_revision = 1 AND e.is_deleted = 0');
 
-    $e->query->select('e.*'); // FIXME: seems too broad.
+    // FIXME: seems too broad.
+    $e->query->select('e.*');
     $e->query->select('ov.label as activity_type, e.id as activity_id');
 
     $e->query->join("og", "!casMailingJoinType civicrm_option_group og ON og.name = 'activity_type'");
@@ -118,4 +96,27 @@ class CRM_Activity_Tokens extends \Civi\Token\AbstractTokenSubscriber {
     }
   }
 
+  /**
+   * Get the basic tokens provided.
+   *
+   * @return array token name => token label
+   */
+  protected function getBasicTokens() {
+    return [
+      'activity_id' => ts('Activity ID'),
+      'activity_type' => ts('Activity Type'),
+      'subject' => ts('Activity Subject'),
+      'details' => ts('Activity Details'),
+      'activity_date_time' => ts('Activity Date-Time'),
+    ];
+  }
+
+  /**
+   * Get the tokens for custom fields
+   * @return array token name => token label
+   */
+  protected function getCustomFieldTokens() {
+    return CRM_Utils_Token::getCustomFieldTokens('Activity');
+  }
+
 }