From 0a6789e4d220814a5cffa1dcd7495d11162786f9 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sat, 6 Nov 2021 10:12:15 +1300 Subject: [PATCH] Remove isset from Datasource.tpl This comes up on the first import contact screen --- CRM/Contact/Import/Form/DataSource.php | 13 +++++++++++ CRM/Core/Form.php | 22 +++++++++++++++++-- .../CRM/Contact/Import/Form/DataSource.tpl | 2 +- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/CRM/Contact/Import/Form/DataSource.php b/CRM/Contact/Import/Form/DataSource.php index ead2b2435d..e36b492d12 100644 --- a/CRM/Contact/Import/Form/DataSource.php +++ b/CRM/Contact/Import/Form/DataSource.php @@ -28,6 +28,19 @@ class CRM_Contact_Import_Form_DataSource extends CRM_Core_Form { private $_dataSourceClass; + /** + * Get any smarty elements that may not be present in the form. + * + * To make life simpler for smarty we ensure they are set to null + * rather than unset. This is done at the last minute when $this + * is converted to an array to be assigned to the form. + * + * @return array + */ + public function getOptionalSmartyElements(): array { + return ['disableUSPS']; + } + /** * Set variables up before form is built. * diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index b04744fded..fce332f774 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -908,7 +908,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page { $params['country'] = $params["country-{$this->_bltID}"] = $params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($params["billing_country_id-{$this->_bltID}"]); } - list($hasAddressField, $addressParams) = CRM_Contribute_BAO_Contribution::getPaymentProcessorReadyAddressParams($params, $this->_bltID); + [$hasAddressField, $addressParams] = CRM_Contribute_BAO_Contribution::getPaymentProcessorReadyAddressParams($params, $this->_bltID); if ($hasAddressField) { $params = array_merge($params, $addressParams); } @@ -1022,6 +1022,19 @@ class CRM_Core_Form extends HTML_QuickForm_Page { $this->_options = $options; } + /** + * Get any smarty elements that may not be present in the form. + * + * To make life simpler for smarty we ensure they are set to null + * rather than unset. This is done at the last minute when $this + * is converted to an array to be assigned to the form. + * + * @return array + */ + public function getOptionalSmartyElements(): array { + return []; + } + /** * Render form and return contents. * @@ -1035,6 +1048,11 @@ class CRM_Core_Form extends HTML_QuickForm_Page { $content['formName'] = $this->getName(); // CRM-15153 $content['formClass'] = CRM_Utils_System::getClassName($this); + foreach ($this->getOptionalSmartyElements() as $string) { + if (!array_key_exists($string, $content)) { + $content[$string] = NULL; + } + } return $content; } @@ -1520,7 +1538,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page { } // Handle custom field if (strpos($name, 'custom_') === 0 && is_numeric($name[7])) { - list(, $id) = explode('_', $name); + [, $id] = explode('_', $name); $label = $props['label'] ?? CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', 'label', $id); $gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', 'option_group_id', $id); if (CRM_Utils_Array::value('context', $props) != 'search') { diff --git a/templates/CRM/Contact/Import/Form/DataSource.tpl b/templates/CRM/Contact/Import/Form/DataSource.tpl index 9ec25937a3..5009af8a19 100644 --- a/templates/CRM/Contact/Import/Form/DataSource.tpl +++ b/templates/CRM/Contact/Import/Form/DataSource.tpl @@ -83,7 +83,7 @@ { /if} - {if isset($form.disableUSPS)} + {if $form.disableUSPS} {$form.disableUSPS.html} -- 2.25.1