--- /dev/null
+<?php
+
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved. |
+ | |
+ | 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 |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ * Class CRM_Case_Tokens
+ *
+ * Generate "case.*" tokens.
+ */
+class CRM_Case_Tokens extends CRM_Core_EntityTokens {
+
+ /**
+ * Get the entity name for api v4 calls.
+ *
+ * @return string
+ */
+ protected function getApiEntityName(): string {
+ return 'Case';
+ }
+
+}
return implode(', ', $ret);
}
// Format date fields
- elseif ($entityArray[$token] && $fieldType == CRM_Utils_Type::T_DATE) {
+ elseif ($entityArray[$token] && in_array($fieldType, [CRM_Utils_Type::T_DATE, CRM_Utils_Type::T_TIMESTAMP, (CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME)])) {
return CRM_Utils_Date::customFormat($entityArray[$token]);
}
return implode(', ', (array) $entityArray[$token]);
$customTokens = [];
$tokenName = $usedForTokenWidget ? "{contribution.custom_%d}" : "custom_%d";
foreach (CRM_Core_BAO_CustomField::getFields($entity) as $id => $info) {
- $customTokens[sprintf($tokenName, $id)] = $info['label'];
+ $customTokens[sprintf($tokenName, $id)] = $info['label'] . ' :: ' . $info['groupTitle'];
}
return $customTokens;
$tokens = CRM_Core_SelectValues::caseTokens();
$this->assertEquals($this->getCaseTokens(), $tokens);
$caseID = $this->getCaseID();
- $tokenHtml = CRM_Utils_Token::replaceCaseTokens($caseID, implode("\n", array_keys($this->getCaseTokens())), ['case' => $this->getCaseTokenKeys()]);
+ $tokenString = implode("\n", array_keys($this->getCaseTokens()));
+ $tokenHtml = CRM_Utils_Token::replaceCaseTokens($caseID, $tokenString, ['case' => $this->getCaseTokenKeys()]);
$this->assertEquals($this->getExpectedCaseTokenOutput(), $tokenHtml);
// Now do the same without passing in 'knownTokens'
- $tokenHtml = CRM_Utils_Token::replaceCaseTokens($caseID, implode("\n", array_keys($this->getCaseTokens())));
+ $tokenHtml = CRM_Utils_Token::replaceCaseTokens($caseID, $tokenString);
$this->assertEquals($this->getExpectedCaseTokenOutput(), $tokenHtml);
// And check our deprecated tokens still work.
$tokenHtml = CRM_Utils_Token::replaceCaseTokens($caseID, '{case.case_type_id} {case.status_id}');
$this->assertEquals('Housing Support Ongoing', $tokenHtml);
+
+ $additionalTokensFromProcessor = [
+ '{case.case_type_id}' => 'Case Type ID',
+ '{case.status_id}' => 'Case Status',
+ '{case.case_type_id:name}' => 'Machine name: Case Type',
+ '{case.status_id:name}' => 'Machine name: Case Status',
+ ];
+ $expectedTokens = array_merge($this->getCaseTokens(), $additionalTokensFromProcessor);
+
+ $tokenProcessor = new TokenProcessor(\Civi::dispatcher(), [
+ 'controller' => __CLASS__,
+ 'smarty' => FALSE,
+ 'schema' => ['caseId'],
+ ]);
+ $this->assertEquals($expectedTokens, $tokenProcessor->listTokens());
+ $tokenProcessor->addRow([
+ 'caseId' => $this->getCaseID(),
+ ]);
+ $tokenProcessor->addMessage('html', $tokenString, 'text/plain');
+
+ $tokenProcessor->evaluate();
+ foreach ($tokenProcessor->getRows() as $row) {
+ $text = $row->render('html');
+ }
+ $this->assertEquals($this->getExpectedCaseTokenOutput(), $text);
}
/**
case details
Ongoing
No
-' . $this->case['created_date'] . '
-' . $this->case['modified_date'] . '
+' . CRM_Utils_Date::customFormat($this->case['created_date']) . '
+' . CRM_Utils_Date::customFormat($this->case['modified_date']) . '
';
}
'{case.end_date}' => 'Case End Date',
'{case.details}' => 'Details',
'{case.status_id:label}' => 'Case Status',
- '{case.is_deleted}' => 'Case is in the Trash',
+ '{case.is_deleted:label}' => 'Case is in the Trash',
'{case.created_date}' => 'Created Date',
'{case.modified_date}' => 'Modified Date',
'{case.custom_1}' => 'Enter text here :: Group with field text',