From 7c1523e99b298b548ae70586832cdce2728745c3 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sun, 14 May 2023 13:09:18 +1200 Subject: [PATCH] Additional event tokens --- CRM/Event/Tokens.php | 139 +++++++++++++++++- .../CRM/Event/Form/ParticipantTest.php | 16 +- .../CRM/Utils/TokenConsistencyTest.php | 10 +- .../event_offline_receipt_text.tpl | 11 ++ 4 files changed, 164 insertions(+), 12 deletions(-) diff --git a/CRM/Event/Tokens.php b/CRM/Event/Tokens.php index 5e00e521dd..2968b8c4d4 100644 --- a/CRM/Event/Tokens.php +++ b/CRM/Event/Tokens.php @@ -60,22 +60,86 @@ class CRM_Event_Tokens extends CRM_Core_EntityTokens { 'data_type' => 'String', 'audience' => 'user', ], - 'contact_email' => [ + 'loc_block_id.email_id.email' => [ 'title' => ts('Event Contact Email'), - 'name' => 'contact_email', + 'name' => 'loc_block_id.email_id.email', 'type' => 'calculated', 'options' => NULL, 'data_type' => 'String', 'audience' => 'user', ], - 'contact_phone' => [ + 'loc_block_id.email_2_id.email' => [ + 'title' => ts('Event Contact Email 2'), + 'name' => 'loc_block_id.email_2_id.email', + 'type' => 'calculated', + 'options' => NULL, + 'data_type' => 'String', + 'audience' => 'sysadmin', + ], + 'loc_block_id.phone_id.phone' => [ 'title' => ts('Event Contact Phone'), - 'name' => 'contact_phone', + 'name' => 'loc_block_id.phone_id.phone', 'type' => 'calculated', 'options' => NULL, 'data_type' => '', 'audience' => 'user', ], + 'loc_block_id.phone_id.phone_type_id' => [ + 'title' => ts('Event Contact Phone'), + 'name' => 'loc_block_id.phone_id.phone_type_id', + 'type' => 'calculated', + 'options' => NULL, + 'data_type' => 'Int', + 'audience' => 'sysadmin', + ], + 'loc_block_id.phone_id.phone_type_id:label' => [ + 'title' => ts('Event Contact Phone'), + 'name' => 'loc_block_id.phone_id.phone_type_id:label', + 'type' => 'calculated', + 'options' => NULL, + 'data_type' => 'String', + 'audience' => 'sysadmin', + ], + 'loc_block_id.phone_id.phone_ext' => [ + 'title' => ts('Event Contact Phone Extension'), + 'name' => 'loc_block_id.phone_id.phone_ext', + 'type' => 'calculated', + 'options' => NULL, + 'data_type' => 'String', + 'audience' => 'sysadmin', + ], + 'loc_block_id.phone_2_id.phone' => [ + 'title' => ts('Event Contact Phone 2'), + 'name' => 'loc_block_id.phone_2_id.phone', + 'type' => 'calculated', + 'options' => NULL, + 'data_type' => '', + 'audience' => 'sysadmin', + ], + 'loc_block_id.phone_2_id.phone_type_id' => [ + 'title' => ts('Event Contact Phone'), + 'name' => 'loc_block_id.phone_2_id.phone_type_id', + 'type' => 'calculated', + 'options' => NULL, + 'data_type' => 'Int', + 'audience' => 'sysadmin', + ], + 'loc_block_id.phone_2_id.phone_type_id:label' => [ + 'title' => ts('Event Contact Phone 2'), + 'name' => 'loc_block_id.phone_2_id.phone_type_id:label', + 'type' => 'calculated', + 'options' => NULL, + 'data_type' => 'String', + 'audience' => 'sysadmin', + ], + 'loc_block_id.phone_2_id.phone_ext' => [ + 'title' => ts('Event Contact Phone 2 Extension'), + 'name' => 'loc_block_id.phone_2_id.phone_ext', + 'type' => 'calculated', + 'options' => NULL, + 'data_type' => 'String', + 'audience' => 'sysadmin', + ], ]; } @@ -118,7 +182,25 @@ class CRM_Event_Tokens extends CRM_Core_EntityTokens { 'loc_block_id.address_id.state_province_id:label', 'loc_block_id.address_id.postal_code', 'loc_block_id.email_id.email', + 'loc_block_id.email_2_id.email', 'loc_block_id.phone_id.phone', + 'loc_block_id.phone_id.phone_type_id', + 'loc_block_id.phone_id.phone_ext', + 'loc_block_id.phone_id.phone_type_id:label', + 'loc_block_id.phone_2_id.phone', + 'loc_block_id.phone_2_id.phone_type_id', + 'loc_block_id.phone_2_id.phone_ext', + 'loc_block_id.phone_2_id.phone_type_id:label', + 'confirm_email_text', + 'is_show_location', + 'is_show_location:label', + 'is_public', + 'is_public:label', + 'is_monetary:label', + 'event_type_id:label', + 'event_type_id:name', + 'pay_later_text', + 'pay_later_receipt', 'custom.*', ], $this->getExposedFields())) ->execute()->first(); @@ -133,10 +215,11 @@ class CRM_Event_Tokens extends CRM_Core_EntityTokens { $tokens['registration_url']['text/html'] = \CRM_Utils_System::url('civicrm/event/register', 'reset=1&id=' . $eventID, TRUE, NULL, FALSE, TRUE); $tokens['start_date']['text/html'] = !empty($event['start_date']) ? new DateTime($event['start_date']) : ''; $tokens['end_date']['text/html'] = !empty($event['end_date']) ? new DateTime($event['end_date']) : ''; - $tokens['event_type_id:label']['text/html'] = CRM_Core_PseudoConstant::getLabel('CRM_Event_BAO_Event', 'event_type_id', $event['event_type_id']); - $tokens['event_type_id:name']['text/html'] = CRM_Core_PseudoConstant::getName('CRM_Event_BAO_Event', 'event_type_id', $event['event_type_id']); - $tokens['contact_phone']['text/html'] = $event['loc_block_id.phone_id.phone']; $tokens['contact_email']['text/html'] = $event['loc_block_id.email_id.email']; + $tokens['contact_phone']['text/html'] = $event['loc_block_id.phone_id.phone']; + // We use text/plain for fields which should be converted to html when used in html content. + $tokens['confirm_email_text']['text/plain'] = $event['confirm_email_text']; + $tokens['pay_later_text']['text/plain'] = $event['pay_later_text']; foreach ($this->getTokenMetadata() as $fieldName => $fieldSpec) { if (!isset($tokens[$fieldName])) { @@ -168,6 +251,7 @@ class CRM_Event_Tokens extends CRM_Core_EntityTokens { protected function getExposedFields(): array { return [ 'event_type_id', + 'event_type_id:label', 'title', 'id', 'pay_later_receipt', @@ -175,6 +259,47 @@ class CRM_Event_Tokens extends CRM_Core_EntityTokens { 'end_date', 'summary', 'description', + 'is_show_location', + 'is_public', + 'confirm_email_text', + 'is_monetary', + ]; + } + + /** + * Get any overrides for token metadata. + * + * This is most obviously used for setting the audience, which + * will affect widget-presence. + * + * Changing the audience is done in order to simplify the + * UI for more general users. + * + * @return \string[][] + */ + protected function getTokenMetadataOverrides(): array { + return [ + 'is_public' => ['audience' => 'sysadmin'], + 'is_show_location' => ['audience' => 'sysadmin'], + 'is_monetary' => ['audience' => 'sysadmin'], + ]; + } + + /** + * These tokens still work but we don't advertise them. + * + * We will actively remove from the following places + * - scheduled reminders + * - add to 'blocked' on pdf letter & email + * + * & then at some point start issuing warnings for them. + * + * @return string[] + */ + protected function getDeprecatedTokens(): array { + return [ + 'contact_phone' => 'loc_block_id.phone_id.phone', + 'contact_email' => 'loc_block_id.email_id.email', ]; } diff --git a/tests/phpunit/CRM/Event/Form/ParticipantTest.php b/tests/phpunit/CRM/Event/Form/ParticipantTest.php index feece194bf..ec11518b78 100644 --- a/tests/phpunit/CRM/Event/Form/ParticipantTest.php +++ b/tests/phpunit/CRM/Event/Form/ParticipantTest.php @@ -1,6 +1,8 @@ formatMoneyInput(1550.55), + 'event.loc_block_id.phone_id.phone:::1235', + 'event.loc_block_id.phone_id.phone_type_id:label:::Mobile', + 'event.loc_block_id.phone_id.phone_ext:::456', + 'event.confirm_email_text::Just do it', ]); $this->callAPISuccess('Email', 'delete', ['id' => $email['id']]); @@ -336,7 +342,15 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { $submittedValues['contact_id'] = $this->ids['Contact']['event'] = $this->individualCreate(); if (!empty($eventParams['is_monetary'])) { - $event = $this->eventCreatePaid($eventParams, [['name' => 'big', 'amount' => 1550.55]]); + $phone = Phone::create()->setValues(['phone' => 1235, 'phone_type_id:name' => 'Mobile', 'phone_ext' => 456])->execute()->first(); + $locationBlockID = LocBlock::create()->setValues(['phone_id' => $phone['id']])->execute()->first()['id']; + $event = $this->eventCreatePaid(array_merge([ + 'name' => 'big', + 'amount' => 1550.55, + 'loc_block_id' => $locationBlockID, + 'confirm_email_text' => "Just do it\n Now", + 'is_show_location' => TRUE, + ], $eventParams), [['name' => 'big', 'amount' => 1550.55]]); $submittedValues = array_merge($this->getRecordContributionParams('Partially paid', 'Pending'), $submittedValues); } else { diff --git a/tests/phpunit/CRM/Utils/TokenConsistencyTest.php b/tests/phpunit/CRM/Utils/TokenConsistencyTest.php index ae0e0dd770..f6031996c4 100644 --- a/tests/phpunit/CRM/Utils/TokenConsistencyTest.php +++ b/tests/phpunit/CRM/Utils/TokenConsistencyTest.php @@ -647,8 +647,8 @@ event.start_date :October 21st, 2008 event.end_date :October 23rd, 2008 event.event_type_id:label :Conference event.summary :If you have any CiviCRM related issues or want to track where CiviCRM is heading, Sign up now -event.contact_email :event@example.com -event.contact_phone :456 789 +event.loc_block_id.email_id.email :event@example.com +event.loc_block_id.phone_id.phone :456 789 event.description :event description event.location :15 Walton St Emerald City, Maine 90210 @@ -657,6 +657,7 @@ event.info_url :' . CRM_Utils_System::url('civicrm/event/info', NULL, TRUE) . '& event.registration_url :' . CRM_Utils_System::url('civicrm/event/register', NULL, TRUE) . '&reset=1&id=1 event.pay_later_receipt : event.custom_1 :my field +event.confirm_email_text : '; } @@ -946,14 +947,15 @@ United States', $tokenProcessor->getRow(0)->render('message')); '{event.end_date}' => 'Event End Date', '{event.event_type_id:label}' => 'Type', '{event.summary}' => 'Event Summary', - '{event.contact_email}' => 'Event Contact Email', - '{event.contact_phone}' => 'Event Contact Phone', + '{event.loc_block_id.email_id.email}' => 'Event Contact Email', + '{event.loc_block_id.phone_id.phone}' => 'Event Contact Phone', '{event.description}' => 'Event Description', '{event.location}' => 'Event Location', '{event.info_url}' => 'Event Info URL', '{event.registration_url}' => 'Event Registration URL', '{event.pay_later_receipt}' => 'Pay Later Receipt Text', '{event.' . $this->getCustomFieldName('text') . '}' => 'Enter text here :: Group with field text', + '{event.confirm_email_text}' => 'Confirmation Email Text', ]; } diff --git a/tests/templates/message_templates/event_offline_receipt_text.tpl b/tests/templates/message_templates/event_offline_receipt_text.tpl index 99cd01966a..1df2318235 100644 --- a/tests/templates/message_templates/event_offline_receipt_text.tpl +++ b/tests/templates/message_templates/event_offline_receipt_text.tpl @@ -5,6 +5,17 @@ contact.id:::{contact.id} event.id:::{event.id} participant.id:::{participant.id} event.title:::{event.title} +event.end_date|crmDate:"%Y%m%d"::{event.end_date|crmDate:"%Y%m%d"} +event.loc_block_id.phone_id.phone:::{event.loc_block_id.phone_id.phone} +event.loc_block_id.phone_id.phone_type_id:label:::{event.loc_block_id.phone_id.phone_type_id:label} +event.loc_block_id.phone_id.phone_ext:::{event.loc_block_id.phone_id.phone_ext} +event.loc_block_id.phone_2_id.phone:::{event.loc_block_id.phone_id.phone_2} +event.loc_block_id.phone_2_id.phone_type_id:label:::{event.loc_block_id.phone_id.phone_type_id_2:label} +event.loc_block_id.phone_2_id.phone_ext:::{event.loc_block_id.phone_id.phone_ext_2} +event.confirm_email_text::{event.confirm_email_text} +event.is_show_location|boolean::{event.is_show_location|boolean} +event.is_public|boolean::{event.is_public|boolean} +participant.participant_role_id:name::{participant.participant_role_id:name} participant.status_id:name:::{participant.status_id:name} email:::{$email} event.pay_later_receipt:::{event.pay_later_receipt} -- 2.25.1