* @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) {
$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) {
'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',
]
);
}
+ else {
+ $form->addOptionalQuickFormElement($tagField);
+ }
CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_file', NULL, FALSE, TRUE, "file_taglist_$i");
}
}
<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} - {$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} {$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}
{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/>