From 8d0370a195fcc93569b37aac978567b593d1ad75 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 17 Jan 2022 21:33:03 +1300 Subject: [PATCH] Ensure tags fields are assigned to tpl for email form test --- CRM/Activity/Form/Activity.php | 2 +- CRM/Core/BAO/File.php | 16 +++++++++------- CRM/Core/Form/Tag.php | 1 + templates/CRM/Form/attachment.tpl | 20 ++++++++++---------- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/CRM/Activity/Form/Activity.php b/CRM/Activity/Form/Activity.php index 4845e864e1..ab071e004a 100644 --- a/CRM/Activity/Form/Activity.php +++ b/CRM/Activity/Form/Activity.php @@ -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); } /** diff --git a/CRM/Core/BAO/File.php b/CRM/Core/BAO/File.php index dc2e7ac026..150c3b6e31 100644 --- a/CRM/Core/BAO/File.php +++ b/CRM/Core/BAO/File.php @@ -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"); } } diff --git a/CRM/Core/Form/Tag.php b/CRM/Core/Form/Tag.php index ef8c89df4e..ba4c6cadbf 100644 --- a/CRM/Core/Form/Tag.php +++ b/CRM/Core/Form/Tag.php @@ -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; diff --git a/templates/CRM/Form/attachment.tpl b/templates/CRM/Form/attachment.tpl index 234880aa81..152ea3fcfb 100644 --- a/templates/CRM/Form/attachment.tpl +++ b/templates/CRM/Form/attachment.tpl @@ -17,7 +17,7 @@
{$attVal.cleanName} {if $attVal.description} - {$attVal.description}{/if} - {if !empty($attVal.tag)} + {if $attVal.tag}
{ts}Tags{/ts}: {$attVal.tag}
@@ -27,20 +27,20 @@ {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} -
+
{$attachTitle}
- {if !empty($form.attachFile_1)} - {if !empty($context) && $context EQ 'pcpCampaign'} + {if $form.attachFile_1} + {if $context EQ 'pcpCampaign'}
{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}
{/if} @@ -49,13 +49,13 @@
{ts}Browse to the file 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}
- {if !empty($form.tag_1.html)} + {if $form.tag_1} {/if} - {if !empty($tagsetInfo.file)} + {if $tagsetInfo && $tagsetInfo.file} {include file="CRM/common/Tagset.tpl" tagsetType='file' tableLayout=true tagsetElementName="file_taglist_1"} {/if} {section name=attachLoop start=2 loop=$numAttachments+1} @@ -68,13 +68,13 @@ - {if !empty($form.$tagElement.html)} + {if $form.$tagElement} {/if} - {if !empty($tagsetInfo.file)} + {if $tagsetInfo && $tagsetInfo.file} {include file="CRM/common/Tagset.tpl" tagsetType='file' tableLayout=true tagsetElementName="file_taglist_$index"} {/if} {/section} @@ -92,7 +92,7 @@ {if $attVal.deleteURLArgs} {/if} - {if !empty($attVal.tag)} + {if $attVal.tag}
{ts}Tags{/ts}: {$attVal.tag}
-- 2.25.1
{$form.tag_1.label}
{$form.tag_1.html}
{$form.attachFile_1.label} {$form.$attachName.html} {$form.$attachDesc.html}
{$form.$tagElement.label}
{$form.$tagElement.html}