// 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']);
$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.
*/