show processed token in greeting dropdown
authorSunil Pawar <sunil@skvare.com>
Mon, 27 Sep 2021 16:07:55 +0000 (21:37 +0530)
committerSunil Pawar <sunil@skvare.com>
Tue, 19 Oct 2021 06:48:58 +0000 (12:18 +0530)
replace with new token mechanism

correcting syntax

style fix

CRM/Contact/Form/Edit/CommunicationPreferences.php
templates/CRM/Admin/Form/Options.tpl

index b5c9def4b55da1bff90459858d504ef3a32d43a6..41d7e0f16925a81abde6c1a1f0d6dde26a4b0c48 100644 (file)
@@ -82,8 +82,30 @@ class CRM_Contact_Form_Edit_CommunicationPreferences {
         'greeting_type' => $greeting,
       ];
 
-      //add addressee in Contact form
+      // Add addressee in Contact form.
       $greetingTokens = CRM_Core_PseudoConstant::greeting($filter);
+
+      // Instead of showing smarty token with/o conditional logic in Drop down
+      // list, show processed token (Only in Contact Edit mode).
+      // Get Description of each greeting.
+      $greetingTokensDescription = CRM_Core_PseudoConstant::greeting($filter, 'description');
+      if ($form->_contactId) {
+        $renderedGreetingTokens = CRM_Core_TokenSmarty::render($greetingTokens,
+          [
+            'contactId' => $form->_contactId,
+          ]
+        );
+        foreach ($greetingTokens as $key => &$emailGreetingString) {
+          if ($emailGreetingString) {
+            $emailGreetingString = $renderedGreetingTokens[$key];
+            $emailGreetingString = CRM_Core_DAO::escapeString(CRM_Utils_String::stripSpaces($emailGreetingString));
+            if (!empty($greetingTokensDescription[$key])) {
+              // Append description to processed greeting.
+              $emailGreetingString .= ' ( ' . $greetingTokensDescription[$key] . ' )';
+            }
+          }
+        }
+      }
       if (!empty($greetingTokens)) {
         $form->addElement('select', $fields['field'], $fields['label'],
           [
index 35a857db87beecfd85653eea01b2b3eec1d6e1e2..7ce72eb8ec76a19b61903b1e827574e5581dedc7 100644 (file)
                 <td>{$form.description.html}<br />
             {if $gName eq 'activity_type'}
                <span class="description">{ts}Description is included at the top of the activity edit and view pages for this type of activity.{/ts}</span>
+            {elseif $gName eq 'email_greeting' || $gName eq 'postal_greeting' || $gName eq  'addressee'}
+                <span class="description">{ts}Description will be appended to processed greeting.{/ts}</span>
+            {/if}
                 </td>
               </tr>
-            {/if}
         {/if}
         {if $gName eq 'participant_status'}
               <tr class="crm-admin-options-form-block-visibility_id">