Ensure tags fields are assigned to tpl for email form test
authorEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 17 Jan 2022 08:33:03 +0000 (21:33 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 13 Apr 2022 01:22:37 +0000 (13:22 +1200)
CRM/Activity/Form/Activity.php
CRM/Core/BAO/File.php
CRM/Core/Form/Tag.php
templates/CRM/Form/attachment.tpl

index 4845e864e13d4be27282d8b717fc12654de045e3..ab071e004a693f9c25bfbba8067d194d25905dd6 100644 (file)
@@ -526,7 +526,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
    * @return array
    */
   public function getOptionalQuickFormElements(): array {
-    return ['separation', 'tag'];
+    return array_merge(['separation', 'tag'], $this->optionalQuickFormElements);
   }
 
   /**
index dc2e7ac0266490e19c5967cd40a2fdbead633796..150c3b6e31cfd96317cfbd48b0d5cec4f6363127 100644 (file)
@@ -428,6 +428,8 @@ AND       CEF.entity_id    = %2";
    * @param int $entityID
    * @param null $numAttachments
    * @param bool $ajaxDelete
+   *
+   * @throws \CRM_Core_Exception
    */
   public static function buildAttachment(&$form, $entityTable, $entityID = NULL, $numAttachments = NULL, $ajaxDelete = FALSE) {
 
@@ -442,15 +444,11 @@ AND       CEF.entity_id    = %2";
     $maxFileSize = $config->maxFileSize ? $config->maxFileSize : 2;
 
     $currentAttachmentInfo = self::getEntityFile($entityTable, $entityID, TRUE);
-    $totalAttachments = 0;
+    $totalAttachments = $currentAttachmentInfo ? count($currentAttachmentInfo) : 0;
     if ($currentAttachmentInfo) {
-      $totalAttachments = count($currentAttachmentInfo);
       $form->add('checkbox', 'is_delete_attachment', ts('Delete All Attachment(s)'));
-      $form->assign('currentAttachmentInfo', $currentAttachmentInfo);
-    }
-    else {
-      $form->assign('currentAttachmentInfo', NULL);
     }
+    $form->assign('currentAttachmentInfo', $currentAttachmentInfo);
 
     if ($totalAttachments) {
       if ($totalAttachments >= $numAttachments) {
@@ -487,8 +485,9 @@ AND       CEF.entity_id    = %2";
         'placeholder' => ts('Description'),
       ]);
 
+      $tagField = "tag_$i";
       if (!empty($tags)) {
-        $form->add('select', "tag_$i", ts('Tags'), $tags, FALSE,
+        $form->add('select', $tagField, ts('Tags'), $tags, FALSE,
           [
             'id' => "tags_$i",
             'multiple' => 'multiple',
@@ -497,6 +496,9 @@ AND       CEF.entity_id    = %2";
           ]
         );
       }
+      else {
+        $form->addOptionalQuickFormElement($tagField);
+      }
       CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_file', NULL, FALSE, TRUE, "file_taglist_$i");
     }
   }
index ef8c89df4e5039c4d6f6a5c4e084e8bda43525a8..ba4c6cadbff8cc9b944a7de31b500b1177f28bca 100644 (file)
@@ -86,6 +86,7 @@ class CRM_Core_Form_Tag {
       }
     }
 
+    $form->addExpectedSmartyVariable('tagsetInfo');
     if (!empty($tagset)) {
       // assign current tagsets which is used in postProcess
       $form->_tagsetInfo = $tagset;
index 234880aa819d063d9342514c655b9fae2d0b58e2..152ea3fcfb2d5e3098fa22fc0b2ddd06ba17360b 100644 (file)
@@ -17,7 +17,7 @@
                 <div id="attachFileRecord_{$attVal.fileID}">
                   <strong><a href="{$attVal.url}"><i class="crm-i {$attVal.icon}" aria-hidden="true"></i> {$attVal.cleanName}</a></strong>
                   {if $attVal.description}&nbsp;-&nbsp;{$attVal.description}{/if}
-                  {if !empty($attVal.tag)}
+                  {if $attVal.tag}
                     <br />
                     {ts}Tags{/ts}: {$attVal.tag}
                     <br />
         </td>
     </tr>
 {elseif $action NEQ 4}
-    {if !empty($context) && $context EQ 'pcpCampaign'}
+    {if $context EQ 'pcpCampaign'}
       {capture assign=attachTitle}{ts}Include a Picture or an Image{/ts}{/capture}
     {else}
       {capture assign=attachTitle}{ts}Attachment(s){/ts}{/capture}
     {/if}
-    <div class="crm-accordion-wrapper {if (empty($context) || $context NEQ 'pcpCampaign') AND empty($currentAttachmentInfo)}collapsed{/if}">
+    <div class="crm-accordion-wrapper {if (!$context || $context NEQ 'pcpCampaign') AND !$currentAttachmentInfo}collapsed{/if}">
      <div class="crm-accordion-header">
       {$attachTitle}
      </div><!-- /.crm-accordion-header -->
     <div class="crm-accordion-body">
     <div id="attachments">
       <table class="form-layout-compressed">
-      {if !empty($form.attachFile_1)}
-        {if !empty($context) && $context EQ 'pcpCampaign'}
+      {if $form.attachFile_1}
+        {if $context EQ 'pcpCampaign'}
             <div class="description">{ts}You can upload a picture or image to include on your page. Your file should be in .jpg, .gif, or .png format. Recommended image size is 250 x 250 pixels. Images over 360 pixels wide will be automatically resized to fit.{/ts}</div>
         {/if}
         <tr>
             <div class="description">{ts}Browse to the <strong>file</strong> you want to upload.{/ts}{if $maxAttachments GT 1} {ts 1=$maxAttachments}You can have a maximum of %1 attachment(s).{/ts}{/if} {ts 1=$config->maxFileSize}Each file must be less than %1M in size. You can also add a short description.{/ts}</div>
           </td>
         </tr>
-        {if !empty($form.tag_1.html)}
+        {if $form.tag_1}
           <tr>
             <td class="label">{$form.tag_1.label}</td>
             <td><div class="crm-select-container crm-attachment-tags">{$form.tag_1.html}</div></td>
           </tr>
         {/if}
-        {if !empty($tagsetInfo.file)}
+        {if $tagsetInfo && $tagsetInfo.file}
           <tr>{include file="CRM/common/Tagset.tpl" tagsetType='file' tableLayout=true tagsetElementName="file_taglist_1"}</tr>
         {/if}
         {section name=attachLoop start=2 loop=$numAttachments+1}
                 <td class="label">{$form.attachFile_1.label}</td>
                 <td>{$form.$attachName.html}&nbsp;{$form.$attachDesc.html}<a href="#" class="crm-hover-button crm-clear-attachment" style="visibility: hidden;" title="{ts}Clear{/ts}"><i class="crm-i fa-times" aria-hidden="true"></i></a></td>
             </tr>
-            {if !empty($form.$tagElement.html)}
+            {if $form.$tagElement}
             <tr>
               <td class="label">{$form.$tagElement.label}</td>
               <td><div class="crm-select-container crm-attachment-tags">{$form.$tagElement.html}</div></td>
             </tr>
             {/if}
-            {if !empty($tagsetInfo.file)}
+            {if $tagsetInfo && $tagsetInfo.file}
               <tr>{include file="CRM/common/Tagset.tpl" tagsetType='file' tableLayout=true tagsetElementName="file_taglist_$index"}</tr>
             {/if}
         {/section}
@@ -92,7 +92,7 @@
                   {if $attVal.deleteURLArgs}
                    <a href="#" class="crm-hover-button delete-attachment" data-filename="{$attVal.cleanName}" data-args="{$attVal.deleteURLArgs}" title="{ts}Delete File{/ts}"><span class="icon delete-icon"></span></a>
                   {/if}
-                  {if !empty($attVal.tag)}
+                  {if $attVal.tag}
                     <br/>
                     {ts}Tags{/ts}: {$attVal.tag}
                     <br/>