From 3289f07c65090278eb5de88e34f4ab88363c952a Mon Sep 17 00:00:00 2001 From: Kurund Jalmi Date: Fri, 18 Mar 2022 23:29:53 +0000 Subject: [PATCH] add image upload support for pcp account --- CRM/Contact/Form/Contact.php | 2 +- CRM/Core/BAO/UFGroup.php | 2 +- CRM/PCP/Form/PCPAccount.php | 44 ++++++++++++++++++++- templates/CRM/Contact/Page/ContactImage.tpl | 2 +- templates/CRM/UF/Form/Fields.tpl | 9 +++++ 5 files changed, 54 insertions(+), 5 deletions(-) diff --git a/CRM/Contact/Form/Contact.php b/CRM/Contact/Form/Contact.php index 7168f0a9f8..3f11f1cf82 100644 --- a/CRM/Contact/Form/Contact.php +++ b/CRM/Contact/Form/Contact.php @@ -740,7 +740,7 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form { } if ($this->_action == CRM_Core_Action::UPDATE) { - $deleteExtra = json_encode(ts('Are you sure you want to delete contact image.')); + $deleteExtra = json_encode(ts('Are you sure you want to delete the contact image?')); $deleteURL = [ CRM_Core_Action::DELETE => [ 'name' => ts('Delete Contact Image'), diff --git a/CRM/Core/BAO/UFGroup.php b/CRM/Core/BAO/UFGroup.php index 3b7df791c6..9b58efcfa0 100644 --- a/CRM/Core/BAO/UFGroup.php +++ b/CRM/Core/BAO/UFGroup.php @@ -1839,7 +1839,7 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) $selectAttributes = ['class' => 'crm-select2', 'placeholder' => TRUE]; if ($fieldName == 'image_URL' && $mode == CRM_Profile_Form::MODE_EDIT) { - $deleteExtra = json_encode(ts('Are you sure you want to delete contact image.')); + $deleteExtra = json_encode(ts('Are you sure you want to delete the contact image?')); $deleteURL = [ CRM_Core_Action::DELETE => [ 'name' => ts('Delete Contact Image'), diff --git a/CRM/PCP/Form/PCPAccount.php b/CRM/PCP/Form/PCPAccount.php index fd148fdd3e..246a113d78 100644 --- a/CRM/PCP/Form/PCPAccount.php +++ b/CRM/PCP/Form/PCPAccount.php @@ -115,6 +115,33 @@ class CRM_PCP_Form_PCPAccount extends CRM_Core_Form { } CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactID, $fields, $this->_defaults); + + if (!empty($this->_defaults['image_URL'])) { + $this->assign("imageURL", CRM_Utils_File::getImageURL($this->_defaults['image_URL'])); + $this->removeFileRequiredRules('image_URL'); + + $deleteExtra = json_encode(ts('Are you sure you want to delete the contact image?')); + $deleteURL = [ + CRM_Core_Action::DELETE => [ + 'name' => ts('Delete Contact Image'), + 'url' => 'civicrm/contact/image', + 'qs' => 'reset=1&cid=' . $this->_contactID . '&action=delete', + 'extra' => 'onclick = "' . htmlspecialchars("if (confirm($deleteExtra)) this.href+='&confirmed=1'; else return false;") . '"', + ], + ]; + $deleteURL = CRM_Core_Action::formLink($deleteURL, + CRM_Core_Action::DELETE, + [ + 'id' => $this->_contactID, + ], + ts('more'), + FALSE, + 'contact.image.delete', + 'Contact', + $this->_contactID + ); + $this->assign('deleteURL', $deleteURL); + } } //set custom field defaults foreach ($this->_fields as $name => $field) { @@ -181,10 +208,19 @@ class CRM_PCP_Form_PCPAccount extends CRM_Core_Form { $this->assign('campaignName', CRM_Event_PseudoConstant::event($this->_pageId)); } + // get the value from session, this is set if there is any file upload field + $uploadNames = $this->get('uploadNames'); + if (!empty($uploadNames)) { + $buttonName = 'upload'; + } + else { + $buttonName = 'next'; + } + if ($this->_single) { $button = [ [ - 'type' => 'next', + 'type' => $buttonName, 'name' => ts('Save'), 'spacing' => '         ', 'isDefault' => TRUE, @@ -197,7 +233,7 @@ class CRM_PCP_Form_PCPAccount extends CRM_Core_Form { } else { $button[] = [ - 'type' => 'next', + 'type' => $buttonName, 'name' => ts('Continue'), 'spacing' => '         ', 'isDefault' => TRUE, @@ -266,6 +302,10 @@ class CRM_PCP_Form_PCPAccount extends CRM_Core_Form { $this->_contactID = CRM_Contact_BAO_Contact::getFirstDuplicateContact($params, 'Individual', 'Unsupervised', [], FALSE); + if (!empty($params['image_URL'])) { + CRM_Contact_BAO_Contact::processImageParams($params); + } + $contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $this->_fields, $this->_contactID); $this->set('contactID', $contactID); diff --git a/templates/CRM/Contact/Page/ContactImage.tpl b/templates/CRM/Contact/Page/ContactImage.tpl index be9d2e5729..a990d7dc89 100644 --- a/templates/CRM/Contact/Page/ContactImage.tpl +++ b/templates/CRM/Contact/Page/ContactImage.tpl @@ -11,7 +11,7 @@
{$imageURL}
- {if $action eq 0 or $action eq 2} + {if $action eq 0 or $action neq 1}
{$deleteURL}
{/if} {/crmRegion} diff --git a/templates/CRM/UF/Form/Fields.tpl b/templates/CRM/UF/Form/Fields.tpl index 3492371194..b261f2dcbd 100644 --- a/templates/CRM/UF/Form/Fields.tpl +++ b/templates/CRM/UF/Form/Fields.tpl @@ -101,6 +101,15 @@ value="{$formElement.value}" id="{$formElement.name}" > + {elseif ( $profileFieldName eq 'image_URL' )} + {$formElement.html} + {if !empty($imageURL)} +
+
+ {include file="CRM/Contact/Page/ContactImage.tpl"} +
+
+ {/if} {elseif $profileFieldName|substr:0:5 eq 'phone'} {assign var="phone_ext_field" value=$profileFieldName|replace:'phone':'phone_ext'} {$formElement.html} -- 2.25.1