Skip to content
Snippets Groups Projects
Commit 17dae666 authored by Eileen McNaughton's avatar Eileen McNaughton
Browse files

Copy locationBuildForm function back to only class that calls it

parent a823c163
Branches
Tags
No related merge requests found
......@@ -819,7 +819,7 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
// build location blocks.
CRM_Contact_Form_Edit_Lock::buildQuickForm($this);
CRM_Contact_Form_Location::buildQuickForm($this);
$this->buildLocationForm();
// add attachment
$this->addField('image_URL', ['maxlength' => '255', 'label' => ts('Browse/Upload Image'), 'accept' => 'image/png, image/jpeg, image/gif']);
......@@ -883,6 +883,67 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
$this->addButtons($buttons);
}
private function buildLocationForm(): void {
// required for subsequent AJAX requests.
$ajaxRequestBlocks = [];
$generateAjaxRequest = 0;
//build 1 instance of all blocks, without using ajax ...
foreach ($this->_blocks as $blockName => $label) {
$name = strtolower($blockName);
$instances = [1];
if (!empty($_POST[$name]) && is_array($_POST[$name])) {
$instances = array_keys($_POST[$name]);
}
elseif (!empty($this->_values[$name]) && is_array($this->_values[$name])) {
$instances = array_keys($this->_values[$name]);
}
foreach ($instances as $instance) {
if ($instance == 1) {
$this->assign('addBlock', FALSE);
$this->assign('blockId', $instance);
}
else {
//we are going to build other block instances w/ AJAX
$generateAjaxRequest++;
$ajaxRequestBlocks[$blockName][$instance] = TRUE;
}
switch ($blockName) {
case 'Email':
// setDefaults uses this to tell which instance
$this->set('Email_Block_Count', $instance);
CRM_Contact_Form_Edit_Email::buildQuickForm($this, $instance);
// Only display the signature fields if this contact has a CMS account
// because they can only send email if they have access to the CRM
$ufID = $this->_contactId && CRM_Core_BAO_UFMatch::getUFId($this->_contactId);
$this->assign('isAddSignatureFields', (bool) $ufID);
if ($ufID) {
$this->add('textarea', "email[$instance][signature_text]", ts('Signature (Text)'),
['rows' => 2, 'cols' => 40]
);
$this->add('wysiwyg', "email[$instance][signature_html]", ts('Signature (HTML)'),
['rows' => 2, 'cols' => 40]
);
}
break;
default:
// @todo This pattern actually adds complexity compared to filling out a switch statement
// for the limited number of blocks - as we also have to receive the block count
$this->set($blockName . '_Block_Count', $instance);
$formName = 'CRM_Contact_Form_Edit_' . $blockName;
$formName::buildQuickForm($this);
}
}
}
//assign to generate AJAX request for building extra blocks.
$this->assign('generateAjaxRequest', $generateAjaxRequest);
$this->assign('ajaxRequestBlocks', $ajaxRequestBlocks);
}
/**
* Form submission of new/edit contact is processed.
*/
......
......@@ -13,12 +13,15 @@
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*
* @deprecated in CiviCRM 5.66, will be removed around CiviCRM 5.76.
*/
class CRM_Contact_Form_Location {
/**
* Build the form object.
*
* @deprecated in CiviCRM 5.66, will be removed around CiviCRM 5.76.
* @param CRM_Core_Form $form
*/
public static function buildQuickForm(&$form) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment