CRM-15172 - Refactor forms to use addChainSelect method
authorColeman Watts <coleman@civicrm.org>
Sun, 24 Aug 2014 21:05:14 +0000 (22:05 +0100)
committerColeman Watts <coleman@civicrm.org>
Mon, 25 Aug 2014 06:59:49 +0000 (07:59 +0100)
38 files changed:
CRM/Admin/Form/Setting/Localization.php
CRM/Campaign/Form/Petition/Signature.php
CRM/Contact/BAO/Contact/Utils.php
CRM/Contact/Form/Contact.php
CRM/Contact/Form/Domain.php
CRM/Contact/Form/Edit/Address.php
CRM/Contact/Form/Inline/Address.php
CRM/Contact/Form/Search/Criteria.php
CRM/Contact/Form/Search/Custom/Proximity.php
CRM/Contact/Form/Task/Batch.php
CRM/Contact/Form/Task/ProximityCommon.php
CRM/Contribute/Form/AdditionalPayment.php
CRM/Contribute/Form/Contribution.php
CRM/Contribute/Form/Contribution/Confirm.php
CRM/Contribute/Form/Contribution/Main.php
CRM/Contribute/Form/Contribution/OnBehalfOf.php
CRM/Contribute/Form/Contribution/ThankYou.php
CRM/Contribute/Form/ContributionBase.php
CRM/Contribute/Form/UpdateBilling.php
CRM/Core/BAO/Address.php
CRM/Core/BAO/CustomField.php
CRM/Core/BAO/CustomGroup.php
CRM/Core/BAO/UFGroup.php
CRM/Core/Payment/Form.php
CRM/Event/Form/EventFees.php
CRM/Event/Form/ManageEvent/Location.php
CRM/Event/Form/Registration.php
CRM/Event/Form/Registration/AdditionalParticipant.php
CRM/Event/Form/Registration/Confirm.php
CRM/Event/Form/Registration/Register.php
CRM/Member/Form/Membership.php
CRM/PCP/Form/PCPAccount.php
CRM/Profile/Form.php
CRM/Report/Form.php
CRM/Report/Form/Contact/Summary.php
CRM/UF/Form/AbstractPreview.php
templates/CRM/Form/body.tpl
templates/CRM/common/stateCountry.tpl [deleted file]

index 936e7bcd2fddf2246873ce3ef335d54dc81180f6..b893c694183e0e52a0560a3213c8017f04bc8029 100644 (file)
@@ -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();
index 205ad1edc018f5ac579cdfa9c1f9ac20af6db379..bc75840fa2a474c59596dc059d02ce90df2d51c7 100644 (file)
@@ -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);
index 3b1001edb5466df04a12c03ee9ee44442450026b..67a0e1f9031844faed73443ab0b75a310c494292 100644 (file)
@@ -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
-    );
   }
 
   /**
index 2ca53a78969caa36deb6f003306714c64256a195..2842a8015bb492eb35725dd3be9545d4d336248b 100644 (file)
@@ -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
-          )
-        );
-      }
-    }
   }
 
   /**
index b958f8fd27cb37dadc0fc748d739fc90bfeb68cb..801c555d85b1263828f6fbdd75557c5010e5ff06 100644 (file)
@@ -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;
index b32044a09ff872e79b10597374a088db938acd10..11d47f9cfb5322aeee8093951c7e47000a572076 100644 (file)
@@ -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
    *
index d55ad645fdb8e92cbb15f6cb1710ded8d5827cd3..cf7abf53029431f9058a85662321736c96acde69 100644 (file)
@@ -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;
   }
 
index 2513ee646076634f9ef0355ddcfabb009ba0aaf5..8f5b69af5935fca1ee2ba88abd1c97693eff81e7 100644 (file)
@@ -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'));
index c9d1dfcd4d7e245825cbaf2360c583dbfdd847b2..d6a4455375f2eddd3a34e7451a7ea79dff23a99e 100644 (file)
@@ -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
      */
index 9746fbf9fb1d0f42633da40ff631cbe804be338f..815488ce7cff0888e7f612f913f8ee02dc9dd763 100644 (file)
@@ -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;
   }
 
index 0e3462d8a39c0b1b5780b24834e63ec92cfb7bca..58ad97352d1d34f91bb3234646e370533611c0f1 100644 (file)
@@ -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);
   }
 
index cdb100897494545b140f7522b60c4447bab43a1d..e2e56864f2eededb3644009f931fa4753b1d5fbc 100644 (file)
@@ -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'])) {
index c19f95e0fd7948b1d6a0c34ac5cdf76680896af2..5c98b55173926ed5a79784c914813e82c997ba4f 100644 (file)
@@ -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) {
index 1c294494a51983e7777643c33c20f2c57e215ffe..997f3c40bfb8c2e53f6a42ae2d144589ebebff5d 100644 (file)
@@ -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();
index 6dd1995c23a02f851692b2b757338cda29555d78..30dcc8c9154bc50ab71c22ac7898ce2bdb6eefe0 100644 (file)
@@ -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();
index 11662677cb19200a8c387fc0296a66b03dd18791..a34c0692aaabf2a169ba2191d814ba9fb2ddf554 100644 (file)
@@ -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);
   }
index 1597730d54e4e69559ca8cbab05a479b8271642b..ded9e83f7fe79937094392cd73f48250080fe589 100644 (file)
@@ -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);
 
index d60a8405bc202ca634ef1da78e8c55ae289845c3..8bc1716aef5e05b1f21f36d07d352d25be778b42 100644 (file)
@@ -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);
index bc0d9e48c02fc72179b1c0f2be2fc4d9fc3aebae..cf03cf65cdba391c490927fa3b0976d82b987b52 100644 (file)
@@ -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;
   }
 
index 7d52be6219a4495b1c1c96803dd8184052655b9d..cedff25e641c4fddea0d5f28d527c6063533d3dd 100644 (file)
@@ -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
    *
index 4c90b62952c9d0fde46c5c47bb25a743739d6de6..b80f086842b62e5babd3108d3be9f36a52a28e9e 100644 (file)
@@ -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?
index 8cc623a92f1acb7d099852b4121083821e80625f..a3c4b4995e2ae8153a43670b40a4bbc06eaead19 100644 (file)
@@ -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);
-    }
   }
 
   /**
index 478501d45242a61871a81626f371f97d63a248c6..e26683a53bffdedf75704a8e294bd7dadf551f65 100644 (file)
@@ -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);
index d461af28e43e95036e52c7e77a56c7d0c69aeb3b..91a119b9893943920441bf2e1ed51a7792de8b5a 100644 (file)
@@ -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) {
index 753417c8091d1c99cf3296ddf0b6587af0045977..898bbf90405a8a7d589dca2a082b7787153741ee 100644 (file)
@@ -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';
index 61d72a86cf7881b4d3868cb7bcd42477bc30519f..c105eccaf8c7f94c1cfc7984467d93593d84cc77 100644 (file)
@@ -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;
index 37a9074bb896d17a3d80058b4603f547a43c1921..96b740c85027e0837867c2e0f8a2a023bf93180b 100644 (file)
@@ -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);
index df561596a82dd1097fb9ba628838944d826080d3..1b34e1864887ad44737e39b1156a9a0124167c19 100644 (file)
@@ -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;
   }
index 4106dee295fa1b3cfb8ca1d6b81f03815ca3cf13..69cb4a72728b4d6c535cf8860f4f6aaee20bc544 100644 (file)
@@ -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();
 
index 8b0f44eb3bd6abf10e0920f2766be4314281ea71..6bc49b537b91f448d5038fe8dec6f27773e612f3 100644 (file)
@@ -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) {
index a865ddb8a000163d2a1ee267d10cf7342482f7b7..7b01f96c0dfca67f29c28b517b12174bef7ce051 100644 (file)
@@ -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';
index 4408695533ef07676a9162f8d80d5d9e87a6dcc9..08a9ed75d3b1b754c2c17d21253c1c49148f9500 100644 (file)
@@ -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;
   }
 
index 8f0aec6b6fb80a7a41e851e03f09b5d6001bd5b3..3fcc264132554517c2e2839d797c304d8ba07ba3 100644 (file)
@@ -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();
index 00e2a540247541491056cea63459e1433f03d77f..d5d62e655374a3f1840d1efc0627be525e78c7cb 100644 (file)
@@ -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']
     );
-
   }
 
   /**
index 44d2611616904ffdfe59e12efedad6bb328dd977..7dbc2b3863f2384e1f5f1c7b6a97835ef9e9db6f 100644 (file)
@@ -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;
index 6f1d8fb04f476de0f1716ac026dabffd5767d27f..2a201a8b78b094c3b1b2f429330765c363da6a92 100644 (file)
@@ -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;
   }
 
index 58e860fc64845f8f8614293a6ab79b53fc329717..d951907da040ec0eac1ae216e1ff3d54a235a279 100644 (file)
@@ -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 (file)
index a1e0e2f..0000000
+++ /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}
-<script type="text/javascript">
-  {literal}
-  CRM.$(function($) {
-    var $form = $('form.{/literal}{$form.formClass}{literal}');
-    function chainSelect(e) {
-      var info = $(this).data('chainSelect');
-      var val = info.target.val();
-      var multiple = info.target.attr('multiple');
-      var placeholder = $(this).val() ? "{/literal}{ts escape='js'}Loading{/ts}{literal}..." : info.placeholder;
-      if (multiple) {
-        info.target.html('').prop('disabled', true).crmSelect2({placeholder: placeholder});
-      }
-      else {
-        info.target.html('<option value="">' + placeholder + '</option>').prop('disabled', true).crmSelect2();
-      }
-      if ($(this).val()) {
-        $.getJSON(info.callback, {_value: $(this).val()}, function(data) {
-          var options = '';
-          function buildOptions(data) {
-            $.each(data, function() {
-              if (this.children) {
-                options += '<optgroup label="' + this.name + '">';
-                buildOptions(this.children);
-                options += '</optgroup>';
-              }
-              else if (this.value || !multiple) {
-                options += '<option value="' + this.value + '">' + this.name + '</option>';
-              }
-              else {
-                info.target.crmSelect2({placeholder: this.name});
-              }
-            });
-          }
-          buildOptions(data);
-          info.target.html(options).val(val).prop('disabled', false).trigger('change');
-        });
-      }
-      else {
-        info.target.trigger('change');
-      }
-    }
-    function initField(selector, removePlaceholder) {
-      var $el = $(selector, $form);
-      if (removePlaceholder !== false) {
-        $el.removeAttr('placeholder');
-      }
-      return $el.css('min-width', '20em').crmSelect2();
-    }
-    {/literal}
-    {foreach from=$config->stateCountryMap item=stateCountryMap}
-      {if $stateCountryMap.state_province && $stateCountryMap.county}
-        $('select[name="{$stateCountryMap.state_province}"], select#{$stateCountryMap.state_province}', $form).data('chainSelect', {ldelim}
-          callback: CRM.url('civicrm/ajax/jqCounty'),
-          target: initField('select[name="{$stateCountryMap.county}"], #{$stateCountryMap.county}'),
-          placeholder: "{ts escape='js'}Choose state first{/ts}"
-        {rdelim}).on('change',  chainSelect);
-      {/if}
-      {if $stateCountryMap.country && $stateCountryMap.state_province}
-        initField('select[name="{$stateCountryMap.country}"], select#{$stateCountryMap.country}', false).data('chainSelect', {ldelim}
-          callback: CRM.url('civicrm/ajax/jqState'),
-          target: initField('select[name="{$stateCountryMap.state_province}"], #{$stateCountryMap.state_province}'),
-          placeholder: "{ts escape='js'}Choose country first{/ts}"
-        {rdelim}).on('change', chainSelect).change();
-      {/if}
-    {/foreach}
-    {literal}
-  });
-  {/literal}
-</script>
-{/if}