From c927c1517145aca30a94534fd014233281c8f837 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 24 Aug 2014 22:05:14 +0100 Subject: [PATCH] CRM-15172 - Refactor forms to use addChainSelect method --- CRM/Admin/Form/Setting/Localization.php | 28 +--- CRM/Campaign/Form/Petition/Signature.php | 16 --- CRM/Contact/BAO/Contact/Utils.php | 9 -- CRM/Contact/Form/Contact.php | 17 --- CRM/Contact/Form/Domain.php | 15 -- CRM/Contact/Form/Edit/Address.php | 130 +----------------- CRM/Contact/Form/Inline/Address.php | 14 -- CRM/Contact/Form/Search/Criteria.php | 36 +---- CRM/Contact/Form/Search/Custom/Proximity.php | 21 +-- CRM/Contact/Form/Task/Batch.php | 25 +--- CRM/Contact/Form/Task/ProximityCommon.php | 19 +-- CRM/Contribute/Form/AdditionalPayment.php | 3 - CRM/Contribute/Form/Contribution.php | 3 - CRM/Contribute/Form/Contribution/Confirm.php | 3 - CRM/Contribute/Form/Contribution/Main.php | 3 - .../Form/Contribution/OnBehalfOf.php | 20 +-- CRM/Contribute/Form/Contribution/ThankYou.php | 3 - CRM/Contribute/Form/ContributionBase.php | 9 -- CRM/Contribute/Form/UpdateBilling.php | 5 - CRM/Core/BAO/Address.php | 59 +------- CRM/Core/BAO/CustomField.php | 4 - CRM/Core/BAO/CustomGroup.php | 7 - CRM/Core/BAO/UFGroup.php | 36 +++-- CRM/Core/Payment/Form.php | 33 ++--- CRM/Event/Form/EventFees.php | 3 - CRM/Event/Form/ManageEvent/Location.php | 13 -- CRM/Event/Form/Registration.php | 10 -- .../Registration/AdditionalParticipant.php | 1 - CRM/Event/Form/Registration/Confirm.php | 3 - CRM/Event/Form/Registration/Register.php | 5 - CRM/Member/Form/Membership.php | 3 - CRM/PCP/Form/PCPAccount.php | 15 -- CRM/Profile/Form.php | 20 --- CRM/Report/Form.php | 56 +++----- CRM/Report/Form/Contact/Summary.php | 54 +------- CRM/UF/Form/AbstractPreview.php | 18 --- templates/CRM/Form/body.tpl | 2 - templates/CRM/common/stateCountry.tpl | 96 ------------- 38 files changed, 71 insertions(+), 746 deletions(-) delete mode 100644 templates/CRM/common/stateCountry.tpl diff --git a/CRM/Admin/Form/Setting/Localization.php b/CRM/Admin/Form/Setting/Localization.php index 936e7bcd2f..b893c69418 100644 --- a/CRM/Admin/Form/Setting/Localization.php +++ b/CRM/Admin/Form/Setting/Localization.php @@ -134,33 +134,7 @@ class CRM_Admin_Form_Setting_Localization extends CRM_Admin_Form_Setting { $includeState->setButtonAttributes('remove', array('value' => ts('<< Remove'))); $this->addElement('select', 'defaultContactCountry', ts('Default Country'), array('' => ts('- select -')) + $country); - - /***Default State/Province***/ - $stateCountryMap = array(); - $stateCountryMap[] = array( - 'state_province' => 'defaultContactStateProvince', - 'country' => 'defaultContactCountry', - ); - - $countryDefault = isset($this->_submitValues['defaultContactCountry']) ? $this->_submitValues['defaultContactCountry'] : $config->defaultContactCountry; - - if ($countryDefault) { - $selectStateProvinceOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault); - } - else { - $selectStateProvinceOptions = array('' => ts('- select a country -')); - } - - $i18n->localizeArray($selectStateProvinceOptions, array('context' => 'state_province')); - asort($selectStateProvinceOptions); - - $this->addElement('select', 'defaultContactStateProvince', ts('Default State/Province'), $selectStateProvinceOptions); - - // state country js - CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap); - - $defaults = array(); - CRM_Core_BAO_Address::fixAllStateSelects($form, $defaults); + $this->addChainSelect('defaultContactStateProvince', array('label' => ts('Default State/Province'))); // we do this only to initialize currencySymbols, kinda hackish but works! $config->defaultCurrencySymbol(); diff --git a/CRM/Campaign/Form/Petition/Signature.php b/CRM/Campaign/Form/Petition/Signature.php index 205ad1edc0..bc75840fa2 100644 --- a/CRM/Campaign/Form/Petition/Signature.php +++ b/CRM/Campaign/Form/Petition/Signature.php @@ -289,9 +289,6 @@ class CRM_Campaign_Form_Petition_Signature extends CRM_Core_Form { } $this->setDefaults($this->_defaults); - - // add in all state country selectors for enabled countries - CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults); } public function buildQuickForm() { @@ -602,10 +599,6 @@ class CRM_Campaign_Form_Petition_Signature extends CRM_Core_Form { * @access public */ function buildCustom($id, $name, $viewOnly = FALSE) { - - // create state country map array to hold selectors - $stateCountryMap = array(); - if ($id) { $session = CRM_Core_Session::singleton(); $this->assign("petition", $this->petition); @@ -649,12 +642,6 @@ class CRM_Campaign_Form_Petition_Signature extends CRM_Core_Form { // if state or country in the profile, create map list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2); - if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') { - if (!array_key_exists($index, $stateCountryMap)) { - $stateCountryMap[$index] = array(); - } - $stateCountryMap[$index][$prefixName] = $key; - } CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE); $this->_fields[$key] = $field; @@ -664,9 +651,6 @@ class CRM_Campaign_Form_Petition_Signature extends CRM_Core_Form { } } - // initialize the state country map - CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap); - if ($addCaptcha && !$viewOnly) { $captcha = CRM_Utils_ReCAPTCHA::singleton(); $captcha->add($this); diff --git a/CRM/Contact/BAO/Contact/Utils.php b/CRM/Contact/BAO/Contact/Utils.php index 3b1001edb5..67a0e1f903 100644 --- a/CRM/Contact/BAO/Contact/Utils.php +++ b/CRM/Contact/BAO/Contact/Utils.php @@ -517,15 +517,6 @@ WHERE id={$contactId}; "; ); //build the address block CRM_Contact_Form_Edit_Address::buildQuickForm($form); - - // also fix the state country selector - CRM_Contact_Form_Edit_Address::fixStateSelect($form, - 'address[1][country_id]', - 'address[1][state_province_id]', - "address[1][county_id]", - $countryID, - $stateID - ); } /** diff --git a/CRM/Contact/Form/Contact.php b/CRM/Contact/Form/Contact.php index 2ca53a7896..2842a8015b 100644 --- a/CRM/Contact/Form/Contact.php +++ b/CRM/Contact/Form/Contact.php @@ -551,23 +551,6 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form { $defaults[$name][1]['is_primary'] = TRUE; } } - - // set defaults for country-state widget - if (!empty($defaults['address']) && is_array($defaults['address'])) { - foreach ($defaults['address'] as $blockId => $values) { - CRM_Contact_Form_Edit_Address::fixStateSelect($this, - "address[$blockId][country_id]", - "address[$blockId][state_province_id]", - "address[$blockId][county_id]", - CRM_Utils_Array::value('country_id', - $values, $config->defaultContactCountry - ), - CRM_Utils_Array::value('state_province_id', - $values, $config->defaultContactStateProvince - ) - ); - } - } } /** diff --git a/CRM/Contact/Form/Domain.php b/CRM/Contact/Form/Domain.php index b958f8fd27..801c555d85 100644 --- a/CRM/Contact/Form/Domain.php +++ b/CRM/Contact/Form/Domain.php @@ -144,21 +144,6 @@ class CRM_Contact_Form_Domain extends CRM_Core_Form { $defaults['address'][1]['state_province_id'] = $config->defaultContactStateProvince; } - if (!empty($defaults['address'])) { - foreach ($defaults['address'] as $key => $value) { - CRM_Contact_Form_Edit_Address::fixStateSelect($this, - "address[$key][country_id]", - "address[$key][state_province_id]", - "address[$key][county_id]", - CRM_Utils_Array::value('country_id', $value, - $config->defaultContactCountry - ), - CRM_Utils_Array::value('state_province_id', $value, - $config->defaultContactStateProvince - ) - ); - } - } } $defaults = array_merge($defaults, $domainDefaults); return $defaults; diff --git a/CRM/Contact/Form/Edit/Address.php b/CRM/Contact/Form/Edit/Address.php index b32044a09f..11d47f9cfb 100644 --- a/CRM/Contact/Form/Edit/Address.php +++ b/CRM/Contact/Form/Edit/Address.php @@ -113,9 +113,9 @@ class CRM_Contact_Form_Edit_Address { 'city' => array(ts('City'), $attributes['city'], NULL), 'postal_code' => array(ts('Zip / Postal Code'), array_merge($attributes['postal_code'], array('class' => 'crm_postal_code')), NULL), 'postal_code_suffix' => array(ts('Postal Code Suffix'), array('size' => 4, 'maxlength' => 12, 'class' => 'crm_postal_code_suffix'), NULL), - 'county_id' => array(ts('County'), $attributes['county_id'], NULL), + 'country_id' => array(ts('Country'), $attributes['country_id'], 'country'), 'state_province_id' => array(ts('State / Province'), $attributes['state_province_id'], NULL), - 'country_id' => array(ts('Country'), $attributes['country_id'], NULL), + 'county_id' => array(ts('County'), $attributes['county_id'], NULL), 'geo_code_1' => array(ts('Latitude'), array('size' => 9, 'maxlength' => 11), NULL), 'geo_code_2' => array(ts('Longitude'), array('size' => 9, 'maxlength' => 11), NULL), 'street_number' => array(ts('Street Number'), $attributes['street_number'], NULL), @@ -123,7 +123,6 @@ class CRM_Contact_Form_Edit_Address { 'street_unit' => array(ts('Apt/Unit/Suite'), $attributes['street_unit'], NULL), ); - $stateCountryMap = array(); foreach ($elements as $name => $v) { list($title, $attributes, $select) = $v; @@ -139,47 +138,14 @@ class CRM_Contact_Form_Edit_Address { } } - if (!$attributes) { - $attributes = $attributes[$name]; - } - //build normal select if country is not present in address block if ($name == 'state_province_id' && !$addressOptions['country']) { $select = 'stateProvince'; } if (!$select) { - if ($name == 'country_id' || $name == 'state_province_id' || $name == 'county_id') { - if ($name == 'country_id') { - $stateCountryMap[$blockId]['country'] = "address_{$blockId}_{$name}"; - $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(); - } - elseif ($name == 'state_province_id') { - $stateCountryMap[$blockId]['state_province'] = "address_{$blockId}_{$name}"; - if ($countryDefault) { - $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault); - } - else { - $selectOptions = array('' => ts('- select a country -')); - } - } - elseif ($name == 'county_id') { - $stateCountryMap[$blockId]['county'] = "address_{$blockId}_{$name}"; - if ($form->getSubmitValue("address[{$blockId}][state_province_id]")) { - $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::countyForState($form->getSubmitValue("address[{$blockId}][state_province_id]")); - } - elseif ($form->getSubmitValue("address[{$blockId}][county_id]")) { - $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::county(); - } - else { - $selectOptions = array('' => ts('- select a state -')); - } - } - $form->addElement('select', - "address[$blockId][$name]", - $title, - $selectOptions - ); + if ($name == 'state_province_id' || $name == 'county_id') { + $form->addChainSelect("address[$blockId][$name]"); } else { if ($name == 'address_name') { @@ -194,9 +160,6 @@ class CRM_Contact_Form_Edit_Address { } } else { - if ($name == 'state_province_id') { - $stateCountryMap[$blockId]['state_province'] = "address_{$blockId}_{$name}"; - } $form->addElement('select', "address[$blockId][$name]", $title, @@ -205,8 +168,6 @@ class CRM_Contact_Form_Edit_Address { } } - CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap); - $entityId = NULL; if (!empty($form->_values['address']) && !empty($form->_values['address'][$blockId])) { $entityId = $form->_values['address'][$blockId]['id']; @@ -397,89 +358,6 @@ class CRM_Contact_Form_Edit_Address { return empty($errors) ? TRUE : $errors; } - /** - * @param $form - * @param $countryElementName - * @param $stateElementName - * @param $countyElementName - * @param $countryDefaultValue - * @param null $stateDefaultValue - */ - static function fixStateSelect(&$form, - $countryElementName, - $stateElementName, - $countyElementName, - $countryDefaultValue, - $stateDefaultValue = NULL - ) { - $countryID = $stateID = NULL; - if (isset($form->_elementIndex[$countryElementName])) { - //get the country id to load states - - //first check for submitted value, - //then check for user passed value. - //finally check for element default val. - $submittedVal = $form->getSubmitValue($countryElementName); - if ($submittedVal) { - $countryID = $submittedVal; - } - elseif ($countryDefaultValue) { - $countryID = $countryDefaultValue; - } - else { - $countryID = CRM_Utils_Array::value(0, $form->getElementValue($countryElementName)); - } - } - $stateTitle = ts('State/Province'); - if (isset($form->_fields[$stateElementName]['title'])) { - $stateTitle = $form->_fields[$stateElementName]['title']; - } - - if (isset($form->_elementIndex[$stateElementName])) { - $submittedValState = $form->getSubmitValue($stateElementName); - if ($submittedValState) { - $stateID = $submittedValState; - } - elseif ($stateDefaultValue) { - $stateID = $stateDefaultValue; - } - else { - $stateID = CRM_Utils_Array::value(0, $form->getElementValue($stateElementName)); - } - } - - if (isset($form->_elementIndex[$stateElementName])) { - if ($countryID) { - $stateProvinces = CRM_Core_PseudoConstant::stateProvinceForCountry($countryID); - } - else { - $stateProvinces = CRM_Core_PseudoConstant::stateProvince(); - } - - $stateSelect = & $form->addElement('select', $stateElementName, $stateTitle, - array('' => ts('- select -')) + $stateProvinces); - } - - if (isset($form->_elementIndex[$stateElementName]) && isset($form->_elementIndex[$countyElementName])) { - if ($stateID) { - $counties = CRM_Core_PseudoConstant::countyForState($stateID); - } - else { - $counties = CRM_Core_PseudoConstant::county(); - } - - $form->addElement('select', $countyElementName, ts('County'), array('' => ts('- select -')) + $counties); - } - - // CRM-7296 freeze the select for state if address is shared with household - // CRM-9070 freeze the select for state if it is view only - if (isset($form->_fields) && !empty($form->_fields[$stateElementName]) && - (!empty($form->_fields[$stateElementName]['is_shared']) || !empty($form->_fields[$stateElementName]['is_view'])) && - !empty($stateSelect) - ) { - $stateSelect->freeze(); - } - } - /** * function to set default values for address block * diff --git a/CRM/Contact/Form/Inline/Address.php b/CRM/Contact/Form/Inline/Address.php index d55ad645fd..cf7abf5302 100644 --- a/CRM/Contact/Form/Inline/Address.php +++ b/CRM/Contact/Form/Inline/Address.php @@ -157,20 +157,6 @@ class CRM_Contact_Form_Inline_Address extends CRM_Contact_Form_Inline { $defaults['address'][$this->_locBlockNo] = $address; } - $values = $defaults['address'][$this->_locBlockNo]; - - CRM_Contact_Form_Edit_Address::fixStateSelect($this, - "address[$this->_locBlockNo][country_id]", - "address[$this->_locBlockNo][state_province_id]", - "address[$this->_locBlockNo][county_id]", - CRM_Utils_Array::value('country_id', - $values, $config->defaultContactCountry - ), - CRM_Utils_Array::value('state_province_id', - $values, $config->defaultContactStateProvince - ) - ); - return $defaults; } diff --git a/CRM/Contact/Form/Search/Criteria.php b/CRM/Contact/Form/Search/Criteria.php index 2513ee6460..8f5b69af59 100644 --- a/CRM/Contact/Form/Search/Criteria.php +++ b/CRM/Contact/Form/Search/Criteria.php @@ -295,9 +295,9 @@ class CRM_Contact_Form_Search_Criteria { 'street_address' => array(ts('Street Address'), $attributes['street_address'], NULL, NULL), 'city' => array(ts('City'), $attributes['city'], NULL, NULL), 'postal_code' => array(ts('Zip / Postal Code'), $attributes['postal_code'], NULL, NULL), - 'county' => array(ts('County'), $attributes['county_id'], 'county', TRUE), - 'state_province' => array(ts('State / Province'), $attributes['state_province_id'], 'stateProvince', TRUE), 'country' => array(ts('Country'), $attributes['country_id'], 'country', FALSE), + 'state_province' => array(ts('State / Province'), $attributes['state_province_id'], 'stateProvince', TRUE), + 'county' => array(ts('County'), $attributes['county_id'], 'county', TRUE), 'address_name' => array(ts('Address Name'), $attributes['address_name'], NULL, NULL), 'street_number' => array(ts('Street Number'), $attributes['street_number'], NULL, NULL), 'street_name' => array(ts('Street Name'), $attributes['street_name'], NULL, NULL), @@ -306,7 +306,6 @@ class CRM_Contact_Form_Search_Criteria { $parseStreetAddress = CRM_Utils_Array::value('street_address_parsing', $addressOptions, 0); $form->assign('parseStreetAddress', $parseStreetAddress); - $stateCountryMap = NULL; foreach ($elements as $name => $v) { list($title, $attributes, $select, $multiSelect) = $v; @@ -326,33 +325,8 @@ class CRM_Contact_Form_Search_Criteria { } if ($select) { - $stateCountryMap = array(array( - 'state_province' => 'state_province', - 'country' => 'country', - 'county' => 'county', - )); - if ($select == 'stateProvince') { - if (!empty($formValues['country'])) { - $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($formValues['country']); - } - else { - //if not setdefault any country - $selectElements = CRM_Core_PseudoConstant::$select(); - } - $element = $form->add('select', $name, $title, $selectElements); - } - elseif ($select == 'country') { - $selectElements = array('' => ts('- any -')) + CRM_Core_PseudoConstant::$select(); - $element = $form->add('select', $name, $title, $selectElements); - } - elseif ($select == 'county') { - if ( array_key_exists('state_province', $formValues) && !CRM_Utils_System::isNull($formValues['state_province'])) { - $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::countyForState($formValues['state_province']); - } - else { - $selectElements = array('' => ts('- any -')); - } - $element = $form->add('select', $name, $title, $selectElements); + if ($select == 'stateProvince' || $select == 'county') { + $element = $form->addChainSelect($name); } else { $selectElements = array('' => ts('- any -')) + CRM_Core_PseudoConstant::$select(); @@ -373,8 +347,6 @@ class CRM_Contact_Form_Search_Criteria { } } - CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap); - // extend addresses with proximity search if (!empty($config->geocodeMethod)) { $form->addElement('text', 'prox_distance', ts('Find contacts within'), array('class' => 'six')); diff --git a/CRM/Contact/Form/Search/Custom/Proximity.php b/CRM/Contact/Form/Search/Custom/Proximity.php index c9d1dfcd4d..d6a4455375 100644 --- a/CRM/Contact/Form/Search/Custom/Proximity.php +++ b/CRM/Contact/Form/Search/Custom/Proximity.php @@ -97,7 +97,7 @@ class CRM_Contact_Form_Search_Custom_Proximity extends CRM_Contact_Form_Search_C } /** - * @param $form + * @param CRM_Core_Form $form */ function buildForm(&$form) { @@ -123,23 +123,15 @@ class CRM_Contact_Form_Search_Custom_Proximity extends CRM_Contact_Form_Search_C 'postal_code', ts('Postal Code') ); - $stateCountryMap = array(); - $stateCountryMap[] = array( - 'state_province' => 'state_province_id', - 'country' => 'country_id', - ); + $defaults = array(); if ($countryDefault) { - $stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault); $defaults['country_id'] = $countryDefault; } - else { - $stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(); - } - $form->add('select', 'state_province_id', ts('State/Province'), $stateProvince, FALSE, array('class' => 'crm-select2 huge')); + $form->addChainSelect('state_province_id'); $country = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(); - $form->add('select', 'country_id', ts('Country'), $country, TRUE, array('class' => 'crm-select2 huge')); + $form->add('select', 'country_id', ts('Country'), $country, TRUE, array('class' => 'crm-select2')); $group = array('' => ts('- any group -')) + CRM_Core_PseudoConstant::nestedGroup(); $form->addElement('select', 'group', ts('Group'), $group, array('class' => 'crm-select2 huge')); @@ -147,11 +139,6 @@ class CRM_Contact_Form_Search_Custom_Proximity extends CRM_Contact_Form_Search_C $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE)); $form->addElement('select', 'tag', ts('Tag'), $tag, array('class' => 'crm-select2 huge')); - - // state country js, CRM-5233 - CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap); - CRM_Core_BAO_Address::fixAllStateSelects($form, $defaults); - /** * You can define a custom title for the search form */ diff --git a/CRM/Contact/Form/Task/Batch.php b/CRM/Contact/Form/Task/Batch.php index 9746fbf9fb..815488ce7c 100644 --- a/CRM/Contact/Form/Task/Batch.php +++ b/CRM/Contact/Form/Task/Batch.php @@ -68,12 +68,6 @@ class CRM_Contact_Form_Task_Batch extends CRM_Contact_Form_Task { */ protected $_preserveDefault = TRUE; - /** - * the internal QF names for the state/country/county fields - */ - - protected $_stateCountryCountyFields = array(); - /** * build all the data structures needed to build the form * @@ -146,20 +140,10 @@ class CRM_Contact_Form_Task_Batch extends CRM_Contact_Form_Task { 'household_name', ); - $stateCountryMap = array(); - foreach ($this->_contactIds as $contactId) { $profileFields = $this->_fields; CRM_Core_BAO_Address::checkContactSharedAddressFields($profileFields, $contactId); foreach ($profileFields as $name => $field) { - - // Link state to country, county to state per location per contact - list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2); - if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') { - $stateCountryMap["$index-$contactId"][$prefixName] = "field_{$contactId}_{$field['name']}"; - $this->_stateCountryCountyFields["$index-$contactId"][$prefixName] = "field[{$contactId}][{$field['name']}]"; - } - CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $contactId); if (in_array($field['name'], $preserveDefaultsArray)) { @@ -168,10 +152,6 @@ class CRM_Contact_Form_Task_Batch extends CRM_Contact_Form_Task { } } - CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap); - - - $this->assign('fields', $this->_fields); // don't set the status message when form is submitted. @@ -190,7 +170,7 @@ class CRM_Contact_Form_Task_Batch extends CRM_Contact_Form_Task { * * @access public * - * @return void + * @return array */ function setDefaultValues() { if (empty($this->_fields)) { @@ -212,9 +192,6 @@ class CRM_Contact_Form_Task_Batch extends CRM_Contact_Form_Task { $this->assign('sortName', $sortName); - // now fix all state country selectors - CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults, $this->_stateCountryCountyFields); - return $defaults; } diff --git a/CRM/Contact/Form/Task/ProximityCommon.php b/CRM/Contact/Form/Task/ProximityCommon.php index 0e3462d8a3..58ad97352d 100644 --- a/CRM/Contact/Form/Task/ProximityCommon.php +++ b/CRM/Contact/Form/Task/ProximityCommon.php @@ -77,7 +77,7 @@ class CRM_Contact_Form_Task_ProximityCommon extends CRM_Contact_Form_Task { * * @access public * - * @param $form + * @param CRM_Core_Form $form * @param $proxSearch * * @return void @@ -93,14 +93,7 @@ class CRM_Contact_Form_Task_ProximityCommon extends CRM_Contact_Form_Task { $form->add('text', 'prox_postal_code', ts('Postal Code'), NULL, FALSE); - $defaults = self::setDefaultValues($form); - if (!empty($defaults['prox_country_id'])) { - $stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($defaults['prox_country_id']); - } - else { - $stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(); - } - $form->add('select', 'prox_state_province_id', ts('State/Province'), $stateProvince, $proxRequired); + $form->addChainSelect('prox_state_province_id', array('required' => $proxRequired)); $country = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(); $form->add('select', 'prox_country_id', ts('Country'), $country, $proxRequired); @@ -111,14 +104,6 @@ class CRM_Contact_Form_Task_ProximityCommon extends CRM_Contact_Form_Task { $form->add('select', 'prox_distance_unit', ts('Units'), $proxUnits, $proxRequired); // prox_distance_unit - // state country js, CRM-5233 - $stateCountryMap = array(); - $stateCountryMap[] = array( - 'state_province' => 'prox_state_province_id', - 'country' => 'prox_country_id', - ); - CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap); - CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults); $form->addFormRule(array('CRM_Contact_Form_Task_ProximityCommon', 'formRule'), $form); } diff --git a/CRM/Contribute/Form/AdditionalPayment.php b/CRM/Contribute/Form/AdditionalPayment.php index cdb1008974..e2e56864f2 100644 --- a/CRM/Contribute/Form/AdditionalPayment.php +++ b/CRM/Contribute/Form/AdditionalPayment.php @@ -187,9 +187,6 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract $billingDefaults = $this->getProfileDefaults('Billing', $this->_contactId); $defaults = array_merge($defaults, $billingDefaults); - - // now fix all state country selectors, set correct state based on country - CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults); } if (empty($defaults['trxn_date']) && empty($defaults['trxn_date_time'])) { diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index c19f95e0fd..5c98b55173 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -378,9 +378,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $billingDefaults = $this->getProfileDefaults('Billing', $this->_contactID); $defaults = array_merge($defaults, $billingDefaults); - - // now fix all state country selectors, set correct state based on country - CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults); } if ($this->_id) { diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 1c294494a5..997f3c40bf 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -600,9 +600,6 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr $this->assign('useForMember', $this->get('useForMember')); - // now fix all state country selectors - CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults); - $this->setDefaults($defaults); $this->freeze(); diff --git a/CRM/Contribute/Form/Contribution/Main.php b/CRM/Contribute/Form/Contribution/Main.php index 6dd1995c23..30dcc8c915 100644 --- a/CRM/Contribute/Form/Contribution/Main.php +++ b/CRM/Contribute/Form/Contribution/Main.php @@ -319,9 +319,6 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu $this->_defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince; } - // now fix all state country selectors - CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults); - if ($this->_priceSetId) { if (($this->_useForMember && !empty($this->_currentMemberships)) || $this->_defaultMemTypeId) { $selectedCurrentMemTypes = array(); diff --git a/CRM/Contribute/Form/Contribution/OnBehalfOf.php b/CRM/Contribute/Form/Contribution/OnBehalfOf.php index 11662677cb..a34c0692aa 100644 --- a/CRM/Contribute/Form/Contribution/OnBehalfOf.php +++ b/CRM/Contribute/Form/Contribution/OnBehalfOf.php @@ -166,18 +166,10 @@ class CRM_Contribute_Form_Contribution_OnBehalfOf { $fieldTypes = array_merge($fieldTypes, array('Contribution')); } - $stateCountryMap = array(); foreach ($profileFields as $name => $field) { if (in_array($field['field_type'], $fieldTypes)) { list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2); - if (in_array($prefixName, array( - 'state_province', 'country', 'county'))) { - if (!array_key_exists($index, $stateCountryMap)) { - $stateCountryMap[$index] = array(); - } - - $stateCountryMap[$index][$prefixName] = 'onbehalf[' . $name . ']'; - + if (in_array($prefixName, array('state_province', 'country', 'county'))) { if (count($form->_submitValues)) { $locationTypeId = $field['location_type_id']; if (!empty($form->_submitValues['onbehalf']["country-{$locationTypeId}"]) && @@ -186,8 +178,7 @@ class CRM_Contribute_Form_Contribution_OnBehalfOf { } } } - elseif (in_array($prefixName, array( - 'organization_name', 'email')) && empty($field['is_required'])) { + elseif (in_array($prefixName, array('organization_name', 'email')) && empty($field['is_required'])) { $field['is_required'] = 1; } @@ -195,13 +186,6 @@ class CRM_Contribute_Form_Contribution_OnBehalfOf { } } - if (!empty($stateCountryMap)) { - CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap); - - // now fix all state country selectors - CRM_Core_BAO_Address::fixAllStateSelects($form, CRM_Core_DAO::$_nullArray); - } - $form->assign('onBehalfOfFields', $profileFields); $form->addElement('hidden', 'hidden_onbehalf_profile', 1); } diff --git a/CRM/Contribute/Form/Contribution/ThankYou.php b/CRM/Contribute/Form/Contribution/ThankYou.php index 1597730d54..ded9e83f7f 100644 --- a/CRM/Contribute/Form/Contribution/ThankYou.php +++ b/CRM/Contribute/Form/Contribution/ThankYou.php @@ -226,9 +226,6 @@ class CRM_Contribute_Form_Contribution_ThankYou extends CRM_Contribute_Form_Cont } } - // now fix all state country selectors - CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults); - $this->_submitValues = array_merge($this->_submitValues, $defaults); $this->setDefaults($defaults); diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index d60a8405bc..8bc1716aef 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -679,8 +679,6 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { * @access public */ function buildCustom($id, $name, $viewOnly = FALSE, $profileContactType = NULL, $fieldTypes = NULL) { - $stateCountryMap = array(); - if ($id) { $contactID = $this->getContactID(); @@ -741,11 +739,6 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2); if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') { - if (!array_key_exists($index, $stateCountryMap)) { - $stateCountryMap[$index] = array(); - } - $stateCountryMap[$index][$prefixName] = $key; - if ($prefixName == "state_province") { if ($profileContactType == 'onbehalf') { //CRM-11881: Bypass required-ness check for state/province on Contribution Confirm page @@ -806,8 +799,6 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { $this->assign($name, $fields); - CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap); - if ($addCaptcha && !$viewOnly) { $captcha = CRM_Utils_ReCAPTCHA::singleton(); $captcha->add($this); diff --git a/CRM/Contribute/Form/UpdateBilling.php b/CRM/Contribute/Form/UpdateBilling.php index bc0d9e48c0..cf03cf65cd 100644 --- a/CRM/Contribute/Form/UpdateBilling.php +++ b/CRM/Contribute/Form/UpdateBilling.php @@ -142,7 +142,6 @@ class CRM_Contribute_Form_UpdateBilling extends CRM_Core_Form { $this->_defaults = array(); if ($this->_subscriptionDetails->contact_id) { - $options = array(); $fields = array(); $names = array( 'first_name', 'middle_name', 'last_name', "street_address-{$this->_bltID}", "city-{$this->_bltID}", @@ -172,16 +171,12 @@ class CRM_Contribute_Form_UpdateBilling extends CRM_Core_Form { } } - $config = CRM_Core_Config::singleton(); // set default country from config if no country set if (empty($this->_defaults["billing_country_id-{$this->_bltID}"])) { $this->_defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry; } - // now fix all state country selectors - CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults); - return $this->_defaults; } diff --git a/CRM/Core/BAO/Address.php b/CRM/Core/BAO/Address.php index 7d52be6219..cedff25e64 100644 --- a/CRM/Core/BAO/Address.php +++ b/CRM/Core/BAO/Address.php @@ -628,6 +628,7 @@ ORDER BY civicrm_address.is_primary DESC, address_id ASC"; * @static */ static function allEntityAddress(&$entityElements) { + $addresses = array(); if (empty($entityElements)) { return $addresses; } @@ -645,7 +646,6 @@ WHERE ev.id = %1 ORDER BY civicrm_address.is_primary DESC, civicrm_address.location_type_id DESC, address_id ASC "; $params = array(1 => array($entityId, 'Integer')); - $addresses = array(); $dao = CRM_Core_DAO::executeQuery($sql, $params); $locationCount = 1; while ($dao->fetch()) { @@ -655,63 +655,6 @@ ORDER BY civicrm_address.is_primary DESC, civicrm_address.location_type_id DESC, return $addresses; } - /** - * @param $stateCountryMap - * @param null $defaults - */ - static function addStateCountryMap($stateCountryMap, $defaults = NULL) { - // first fix the statecountry map if needed - if (empty($stateCountryMap)) { - return; - } - - $config = CRM_Core_Config::singleton(); - if (!isset($config->stateCountryMap)) { - $config->stateCountryMap = array(); - } - - $config->stateCountryMap = array_merge($config->stateCountryMap, $stateCountryMap); - } - - /** - * @param $form - * @param $defaults - * @param bool $batchFieldNames - */ - static function fixAllStateSelects(&$form, $defaults, $batchFieldNames = false) { - $config = CRM_Core_Config::singleton(); - $map = null; - if (is_array($batchFieldNames)) { - $map = $batchFieldNames; - } - elseif (!empty($config->stateCountryMap)) { - $map = $config->stateCountryMap; - } - if (!empty($map)) { - foreach ($map as $index => $match) { - if (array_key_exists('state_province', $match) - || array_key_exists('country', $match) - || array_key_exists('county', $match) - ) { - $countryElementName = CRM_Utils_Array::value('country', $match); - $stateProvinceElementName = CRM_Utils_Array::value('state_province', $match); - $countyElementName = CRM_Utils_Array::value('county', $match); - CRM_Contact_Form_Edit_Address::fixStateSelect( - $form, - $countryElementName, - $stateProvinceElementName, - $countyElementName, - CRM_Utils_Array::value($countryElementName, $defaults), - CRM_Utils_Array::value($stateProvinceElementName, $defaults) - ); - } - else { - unset($config->stateCountryMap[$index]); - } - } - } - } - /** * Function to get address sequence * diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index 4c90b62952..b80f086842 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -759,10 +759,6 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { $widget = 'Text'; } - if ($widget == 'Select State/Province' || $widget == 'Select Country') { - $qf->_stateCountryMap[$widget == 'Select Country' ? 'country' : 'state_province'][] = $elementName; - } - $placeholder = $search ? ts('- any -') : ($useRequired ? ts('- select -') : ts('- none -')); // FIXME: Why are select state/country separate widget types? diff --git a/CRM/Core/BAO/CustomGroup.php b/CRM/Core/BAO/CustomGroup.php index 8cc623a92f..a3c4b4995e 100644 --- a/CRM/Core/BAO/CustomGroup.php +++ b/CRM/Core/BAO/CustomGroup.php @@ -1522,13 +1522,6 @@ ORDER BY civicrm_custom_group.weight, CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, $inactiveNeeded, $required); } } - if (!empty($form->_stateCountryMap['state_province']) && !empty($form->_stateCountryMap['country'])) { - foreach ($form->_stateCountryMap['state_province'] as $key => $value) { - $stateCountryMap[$key]['state_province'] = $value; - $stateCountryMap[$key]['country'] = $form->_stateCountryMap['country'][$key]; - } - CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap); - } } /** diff --git a/CRM/Core/BAO/UFGroup.php b/CRM/Core/BAO/UFGroup.php index 478501d452..e26683a53b 100644 --- a/CRM/Core/BAO/UFGroup.php +++ b/CRM/Core/BAO/UFGroup.php @@ -1736,7 +1736,7 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) * @params int $contactID contact id * @params string $usedFor for building up prefixed fieldname for special cases (e.g. onBehalf, Honor) * - * @param $form + * @param CRM_Core_Form $form * @param $field * @param $mode * @param null $contactId @@ -1794,6 +1794,11 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) $name = $fieldName; } + // CRM-15172 - keep track of all the fields we've processed + // This is hackish but we can't always rely on $form->_fields depending on how this is called + static $fieldsProcessed = array(); + $fieldsProcessed[] = $name; + if ($fieldName == 'image_URL' && $mode == CRM_Profile_Form::MODE_EDIT) { $deleteExtra = ts('Are you sure you want to delete contact image.'); $deleteURL = array( @@ -1824,10 +1829,14 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) ); if (substr($fieldName, 0, 14) === 'state_province') { - $form->add('select', $name, $title, - array( - '' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required - ); + $controlField = str_replace('state_province', 'country', $name); + if (isset($form->_fields[$controlField]) || in_array($controlField, $fieldsProcessed)) { + $form->addChainSelect($name, array('label' => $title, 'required' => $required)); + } + else { + $form->add('select', $name, $title, + array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required); + } $config = CRM_Core_Config::singleton(); if (!in_array($mode, array( CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && @@ -1838,10 +1847,7 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) } } elseif (substr($fieldName, 0, 7) === 'country') { - $form->add('select', $name, $title, - array( - '' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required - ); + $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required); $config = CRM_Core_Config::singleton(); if (!in_array($mode, array( CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && @@ -1853,9 +1859,7 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) } elseif (substr($fieldName, 0, 6) === 'county') { if ($addressOptions['county']) { - $form->add('select', $name, $title, - array('' => ts('Choose state first')), $required - ); + $form->addChainSelect($name, array('label' => $title, 'required' => $required)); } } elseif (substr($fieldName, 0, 9) === 'image_URL') { @@ -2233,14 +2237,6 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) 'non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) { $form->addRule($name, ts('Please enter a valid amount.'), 'money'); } - $stateCountryMap = array(); - if (!empty($form->_stateCountryMap['state_province']) && !empty($form->_stateCountryMap['country'])) { - foreach ($form->_stateCountryMap['state_province'] as $key => $value) { - $stateCountryMap[$key]['state_province'] = $value; - $stateCountryMap[$key]['country'] = $form->_stateCountryMap['country'][$key]; - } - CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap); - } if ($rule) { if (!($rule == 'email' && $mode == CRM_Profile_Form::MODE_SEARCH)) { $form->addRule($name, ts('Please enter a valid %1', array(1 => $title)), $rule); diff --git a/CRM/Core/Payment/Form.php b/CRM/Core/Payment/Form.php index d461af28e4..91a119b989 100644 --- a/CRM/Core/Payment/Form.php +++ b/CRM/Core/Payment/Form.php @@ -106,13 +106,9 @@ class CRM_Core_Payment_Form { ); $form->_paymentFields["billing_state_province_id-{$bltID}"] = array( - 'htmlType' => 'select', + 'htmlType' => 'chainSelect', 'name' => "billing_state_province_id-{$bltID}", - 'title' => ts('State / Province'), 'cc_field' => TRUE, - 'attributes' => array( - '' => ts('- select -')) + - CRM_Core_PseudoConstant::stateProvince(), 'is_required' => self::checkRequiredStateProvince($form, "billing_country_id-{$bltID}"), ); @@ -253,15 +249,18 @@ class CRM_Core_Payment_Form { if ($form->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM) { self::setCreditCardFields($form); foreach ($form->_paymentFields as $name => $field) { - if (isset($field['cc_field']) && - $field['cc_field'] - ) { - $form->add($field['htmlType'], - $field['name'], - $field['title'], - $field['attributes'], - $useRequired ? $field['is_required'] : FALSE - ); + if (!empty($field['cc_field'])) { + if ($field['htmlType'] == 'chainSelect') { + $form->addChainSelect($field['name'], array('required' => $useRequired && $field['is_required'])); + } + else { + $form->add($field['htmlType'], + $field['name'], + $field['title'], + $field['attributes'], + $useRequired ? $field['is_required'] : FALSE + ); + } } } @@ -275,12 +274,6 @@ class CRM_Core_Payment_Form { 'currentDate', TRUE ); - // also take care of state country widget - $stateCountryMap = array( - 1 => array('country' => "billing_country_id-{$form->_bltID}", - 'state_province' => "billing_state_province_id-{$form->_bltID}", - )); - CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap); } if ($form->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_BUTTON) { diff --git a/CRM/Event/Form/EventFees.php b/CRM/Event/Form/EventFees.php index 753417c809..898bbf9040 100644 --- a/CRM/Event/Form/EventFees.php +++ b/CRM/Event/Form/EventFees.php @@ -147,9 +147,6 @@ class CRM_Event_Form_EventFees { $billingDefaults = $form->getProfileDefaults('Billing', $form->_contactId); $defaults[$form->_pId] = array_merge($defaults[$form->_pId], $billingDefaults); - // now fix all state country selectors, set correct state based on country - CRM_Core_BAO_Address::fixAllStateSelects($form, $defaults[$form->_pId]); - // // hack to simplify credit card entry for testing // $defaults[$form->_pId]['credit_card_type'] = 'Visa'; // $defaults[$form->_pId]['credit_card_number'] = '4807731747657838'; diff --git a/CRM/Event/Form/ManageEvent/Location.php b/CRM/Event/Form/ManageEvent/Location.php index 61d72a86cf..c105eccaf8 100644 --- a/CRM/Event/Form/ManageEvent/Location.php +++ b/CRM/Event/Form/ManageEvent/Location.php @@ -124,19 +124,6 @@ class CRM_Event_Form_ManageEvent_Location extends CRM_Event_Form_ManageEvent { $defaults['address'][1]['state_province_id'] = $config->defaultContactStateProvince; } - if (!empty($defaults['address'])) { - foreach ($defaults['address'] as $key => $value) { - CRM_Contact_Form_Edit_Address::fixStateSelect($this, - "address[$key][country_id]", - "address[$key][state_province_id]", - "address[$key][county_id]", - CRM_Utils_Array::value('country_id', $value, - $config->defaultContactCountry - ), - CRM_Utils_Array::value('state_province_id', $value) - ); - } - } $defaults['location_option'] = $this->_oldLocBlockId ? 2 : 1; return $defaults; diff --git a/CRM/Event/Form/Registration.php b/CRM/Event/Form/Registration.php index 37a9074bb8..96b740c850 100644 --- a/CRM/Event/Form/Registration.php +++ b/CRM/Event/Form/Registration.php @@ -575,8 +575,6 @@ class CRM_Event_Form_Registration extends CRM_Core_Form { * @access public */ function buildCustom($id, $name, $viewOnly = FALSE) { - $stateCountryMap = $fields = array(); - if ($id) { $button = substr($this->controller->getButtonName(), -4); $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this); @@ -656,20 +654,12 @@ class CRM_Event_Form_Registration extends CRM_Core_Form { $addCaptcha = TRUE; } list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2); - if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') { - if (!array_key_exists($index, $stateCountryMap)) { - $stateCountryMap[$index] = array(); - } - $stateCountryMap[$index][$prefixName] = $key; - } CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE); $this->_fields[$key] = $field; } } - CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap); - if ($addCaptcha && !$viewOnly) { $captcha = CRM_Utils_ReCAPTCHA::singleton(); $captcha->add($this); diff --git a/CRM/Event/Form/Registration/AdditionalParticipant.php b/CRM/Event/Form/Registration/AdditionalParticipant.php index df561596a8..1b34e18648 100644 --- a/CRM/Event/Form/Registration/AdditionalParticipant.php +++ b/CRM/Event/Form/Registration/AdditionalParticipant.php @@ -160,7 +160,6 @@ class CRM_Event_Form_Registration_AdditionalParticipant extends CRM_Event_Form_R if (array_key_exists('participant_campaign_id', $this->_fields)) { $defaults['participant_campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values['event']); } - CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults); return $defaults; } diff --git a/CRM/Event/Form/Registration/Confirm.php b/CRM/Event/Form/Registration/Confirm.php index 4106dee295..69cb4a7272 100644 --- a/CRM/Event/Form/Registration/Confirm.php +++ b/CRM/Event/Form/Registration/Confirm.php @@ -359,9 +359,6 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration { } } - // now fix all state country selectors - CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults); - $this->setDefaults($defaults); $this->freeze(); diff --git a/CRM/Event/Form/Registration/Register.php b/CRM/Event/Form/Registration/Register.php index 8b0f44eb3b..6bc49b537b 100644 --- a/CRM/Event/Form/Registration/Register.php +++ b/CRM/Event/Form/Registration/Register.php @@ -164,8 +164,6 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { } if ($this->_snippet) { - // now fix all state country selectors - CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults); return $this->_defaults; } @@ -197,9 +195,6 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { CRM_Core_BAO_UFGroup::setProfileDefaults($contactID, $fields, $this->_defaults); } - // now fix all state country selectors - CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults); - // Set default payment processor as default payment_processor radio button value if (!empty($this->_paymentProcessors)) { foreach ($this->_paymentProcessors as $pid => $value) { diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index a865ddb8a0..7b01f96c0d 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -403,9 +403,6 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { $billingDefaults = $this->getProfileDefaults('Billing', $this->_contactID); $defaults = array_merge($defaults, $billingDefaults); - // now fix all state country selectors, set correct state based on country - CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults); - // // hack to simplify credit card entry for testing // $defaults['credit_card_type'] = 'Visa'; // $defaults['credit_card_number'] = '4807731747657838'; diff --git a/CRM/PCP/Form/PCPAccount.php b/CRM/PCP/Form/PCPAccount.php index 4408695533..08a9ed75d3 100644 --- a/CRM/PCP/Form/PCPAccount.php +++ b/CRM/PCP/Form/PCPAccount.php @@ -128,7 +128,6 @@ class CRM_PCP_Form_PCPAccount extends CRM_Core_Form { CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactID, $fields, $this->_defaults); } - $stateCountryMap = array(); //set custom field defaults foreach ($this->_fields as $name => $field) { if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) { @@ -138,21 +137,7 @@ class CRM_PCP_Form_PCPAccount extends CRM_Core_Form { ); } } - if ((substr($name, 0, 14) === 'state_province') || (substr($name, 0, 7) === 'country') || (substr($name, 0, 6) === 'county')) { - list($fieldName, $index) = CRM_Utils_System::explode('-', $name, 2); - if (!array_key_exists($index, $stateCountryMap)) { - $stateCountryMap[$index] = array(); - } - $stateCountryMap[$index][$fieldName] = $name; - } - - // also take care of state country widget - if (!empty($stateCountryMap)) { - CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap, $this->_defaults); - } } - // now fix all state country selectors - CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults); return $this->_defaults; } diff --git a/CRM/Profile/Form.php b/CRM/Profile/Form.php index 8f0aec6b6f..3fcc264132 100644 --- a/CRM/Profile/Form.php +++ b/CRM/Profile/Form.php @@ -176,7 +176,6 @@ class CRM_Profile_Form extends CRM_Core_Form { protected $_currentUserID = NULL; protected $_session = NULL; - public $_stateCountryMap = array(); /** * pre processing work done here. * @@ -742,10 +741,6 @@ class CRM_Profile_Form extends CRM_Core_Form { $addCaptcha = array(); $emailPresent = FALSE; - // cache the state country fields. based on the results, we could use our javascript solution - // in create or register mode - $stateCountryMap = array(); - // add the form elements foreach ($this->_fields as $name => $field) { // make sure that there is enough permission to expose this field @@ -762,12 +757,6 @@ class CRM_Profile_Form extends CRM_Core_Form { } list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2); - if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') { - if (!array_key_exists($index, $stateCountryMap)) { - $stateCountryMap[$index] = array(); - } - $stateCountryMap[$index][$prefixName] = $name; - } CRM_Core_BAO_UFGroup::buildProfile($this, $field, $this->_mode); @@ -825,12 +814,6 @@ class CRM_Profile_Form extends CRM_Core_Form { } } - // lets do the defaults, so we can use it for the below state country routines - $this->setDefaultsValues(); - - // also do state country js - CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap, $this->_defaults); - $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, NULL); if ($this->_mode == self::MODE_CREATE) { CRM_Core_BAO_CMSUser::buildForm($this, $this->_gid, $emailPresent, $action); @@ -841,9 +824,6 @@ class CRM_Profile_Form extends CRM_Core_Form { $this->assign('groupId', $this->_gid); - // now fix all state country selectors - CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults); - // if view mode pls freeze it with the done button. if ($this->_action & CRM_Core_Action::VIEW) { $this->freeze(); diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index 00e2a54024..d5d62e6553 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -878,7 +878,7 @@ class CRM_Report_Form extends CRM_Core_Form { } function addFilters() { - $options = $filters = array(); + $filters = array(); $count = 1; foreach ($this->_filters as $table => $attributes) { foreach ($attributes as $fieldName => $field) { @@ -916,17 +916,22 @@ class CRM_Report_Form extends CRM_Core_Form { case CRM_Report_Form::OP_MULTISELECT: case CRM_Report_Form::OP_MULTISELECT_SEPARATOR: // assume a multi-select field - if (!empty($field['options'])) { + if (!empty($field['options']) || $fieldName == 'state_province_id' || $fieldName == 'county_id') { $element = $this->addElement('select', "{$fieldName}_op", ts('Operator:'), $operations); if (count($operations) <= 1) { $element->freeze(); } - $this->addElement('select', "{$fieldName}_value", NULL, $field['options'], array( - 'style' => 'min-width:250px', - 'class' => 'crm-select2', - 'multiple' => TRUE, - 'placeholder' => ts('- select -'), - )); + if ($fieldName == 'state_province_id' || $fieldName == 'county_id') { + $this->addChainSelect($fieldName . '_value', array('multiple' => TRUE, 'label' => NULL)); + } + else { + $this->addElement('select', "{$fieldName}_value", NULL, $field['options'], array( + 'style' => 'min-width:250px', + 'class' => 'crm-select2', + 'multiple' => TRUE, + 'placeholder' => ts('- select -'), + )); + } } break; @@ -966,14 +971,6 @@ class CRM_Report_Form extends CRM_Core_Form { } } } - - $stateCountryMap[] = array( - 'country' => 'country_id_value', - 'state_province' => 'state_province_id_value', - 'county' => 'county_id_value' - ); - CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap); - $this->assign('filters', $filters); } @@ -3426,8 +3423,7 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a * * @return array address fields for construct clause */ - function addAddressFields($groupBy = TRUE, $orderBy = FALSE, $filters = TRUE, $defaults = array( - 'country_id' => TRUE)) { + function addAddressFields($groupBy = TRUE, $orderBy = FALSE, $filters = TRUE, $defaults = array('country_id' => TRUE)) { $addressFields = array( 'civicrm_address' => array( @@ -3524,26 +3520,21 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => - CRM_Core_PseudoConstant::country(), + 'options' => CRM_Core_PseudoConstant::country(), ), 'state_province_id' => array( 'name' => 'state_province_id', 'title' => ts('State/Province'), 'type' => CRM_Utils_Type::T_INT, - 'operatorType' => - CRM_Report_Form::OP_MULTISELECT, - 'options' => - CRM_Core_PseudoConstant::stateProvince(), + 'operatorType' => CRM_Report_Form::OP_MULTISELECT, + 'options' => array(), ), 'county_id' => array( 'name' => 'county_id', 'title' => ts('County'), 'type' => CRM_Utils_Type::T_INT, - 'operatorType' => - CRM_Report_Form::OP_MULTISELECT, - 'options' => - CRM_Core_PseudoConstant::county(), + 'operatorType' => CRM_Report_Form::OP_MULTISELECT, + 'options' => array(), ), ); } @@ -3729,24 +3720,21 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a * - prefix_label Label to give columns from this address table instance * @return array address columns definition */ - function getAddressColumns($options = array()){ - $defaultOptions = array( + function getAddressColumns($options = array()) { + $options += array( 'prefix' => '', 'prefix_label' => '', 'group_by' => TRUE, 'order_by' => TRUE, 'filters' => TRUE, - 'defaults' => array( - ), + 'defaults' => array(), ); - $options = array_merge($defaultOptions,$options); return $this->addAddressFields( $options['group_by'], $options['order_by'], $options['filters'], $options['defaults'] ); - } /** diff --git a/CRM/Report/Form/Contact/Summary.php b/CRM/Report/Form/Contact/Summary.php index 44d2611616..7dbc2b3863 100644 --- a/CRM/Report/Form/Contact/Summary.php +++ b/CRM/Report/Form/Contact/Summary.php @@ -46,9 +46,6 @@ class CRM_Report_Form_Contact_Summary extends CRM_Report_Form { public $_drilldownReport = array('contact/detail' => 'Link to Detail Report'); - /** - * - */ /** * */ @@ -134,55 +131,6 @@ class CRM_Report_Form_Contact_Summary extends CRM_Report_Form { ), ), ), - 'civicrm_address' => - array( - 'dao' => 'CRM_Core_DAO_Address', - 'grouping' => 'contact-fields', - 'fields' => - array( - 'street_address' => - array('default' => TRUE), - 'city' => - array('default' => TRUE), - 'postal_code' => NULL, - 'state_province_id' => - array('title' => ts('State/Province'), - ), - ), - 'filters' => - array( - 'country_id' => - array('title' => ts('Country'), - 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => CRM_Core_PseudoConstant::country(), - ), - 'state_province_id' => - array('title' => ts('State / Province'), - 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => CRM_Core_PseudoConstant::stateProvince(), - ), - ), - 'order_bys' => - array('state_province_id' => array('title' => 'State/Province'), - 'city' => array('title' => 'City'), - 'postal_code' => array('title' => 'Postal Code'), - ), - ), - 'civicrm_country' => - array( - 'dao' => 'CRM_Core_DAO_Country', - 'fields' => - array( - 'name' => - array('title' => 'Country', 'default' => TRUE), - ), - 'order_bys' => - array( - 'name' => - array('title' => 'Country'), - ), - 'grouping' => 'contact-fields', - ), 'civicrm_phone' => array( 'dao' => 'CRM_Core_DAO_Phone', @@ -196,7 +144,7 @@ class CRM_Report_Form_Contact_Summary extends CRM_Report_Form { ), 'grouping' => 'contact-fields', ), - ); + ) + $this->getAddressColumns(array('group_by' => FALSE)); $this->_groupFilter = TRUE; $this->_tagFilter = TRUE; diff --git a/CRM/UF/Form/AbstractPreview.php b/CRM/UF/Form/AbstractPreview.php index 6f1d8fb04f..2a201a8b78 100644 --- a/CRM/UF/Form/AbstractPreview.php +++ b/CRM/UF/Form/AbstractPreview.php @@ -80,33 +80,15 @@ class CRM_UF_Form_AbstractPreview extends CRM_Core_Form { */ function setDefaultValues() { $defaults = array(); - $stateCountryMap = array(); foreach ($this->_fields as $name => $field) { if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($field['name'])) { CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $defaults, NULL, CRM_Profile_Form::MODE_REGISTER); } - - //CRM-5403 - if ((substr($name, 0, 14) === 'state_province') || (substr($name, 0, 7) === 'country') || (substr($name, 0, 6) === 'county')) { - list($fieldName, $index) = CRM_Utils_System::explode('-', $name, 2); - if (!array_key_exists($index, $stateCountryMap)) { - $stateCountryMap[$index] = array(); - } - $stateCountryMap[$index][$fieldName] = $name; - } - } - - // also take care of state country widget - if (!empty($stateCountryMap)) { - CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap, $defaults); } //set default for country. CRM_Core_BAO_UFGroup::setRegisterDefaults($this->_fields, $defaults); - // now fix all state country selectors - CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults); - return $defaults; } diff --git a/templates/CRM/Form/body.tpl b/templates/CRM/Form/body.tpl index 58e860fc64..d951907da0 100644 --- a/templates/CRM/Form/body.tpl +++ b/templates/CRM/Form/body.tpl @@ -23,8 +23,6 @@ | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ *} -{include file="CRM/common/stateCountry.tpl"} - {if $form.javascript} {$form.javascript} {/if} diff --git a/templates/CRM/common/stateCountry.tpl b/templates/CRM/common/stateCountry.tpl deleted file mode 100644 index a1e0e2f18b..0000000000 --- a/templates/CRM/common/stateCountry.tpl +++ /dev/null @@ -1,96 +0,0 @@ -{* - +--------------------------------------------------------------------+ - | CiviCRM version 4.5 | - +--------------------------------------------------------------------+ - | Copyright CiviCRM LLC (c) 2004-2014 | - +--------------------------------------------------------------------+ - | This file is a part of CiviCRM. | - | | - | CiviCRM is free software; you can copy, modify, and distribute it | - | under the terms of the GNU Affero General Public License | - | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | - | | - | CiviCRM is distributed in the hope that it will be useful, but | - | WITHOUT ANY WARRANTY; without even the implied warranty of | - | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | - | See the GNU Affero General Public License for more details. | - | | - | You should have received a copy of the GNU Affero General Public | - | License and the CiviCRM Licensing Exception along | - | with this program; if not, contact CiviCRM LLC | - | at info[AT]civicrm[DOT]org. If you have questions about the | - | GNU Affero General Public License or the licensing of CiviCRM, | - | see the CiviCRM license FAQ at http://civicrm.org/licensing | - +--------------------------------------------------------------------+ -*} -{if $config->stateCountryMap} - -{/if} -- 2.25.1