CRM-15172 - Refactor forms to use addChainSelect method
[civicrm-core.git] / CRM / Admin / Form / Setting / Localization.php
index 16fcc9a480d54a19c03dcd678cad2b77b130a738..b893c694183e0e52a0560a3213c8017f04bc8029 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -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();
@@ -195,6 +169,11 @@ class CRM_Admin_Form_Setting_Localization extends CRM_Admin_Form_Setting {
     parent::buildQuickForm();
   }
 
+  /**
+   * @param $fields
+   *
+   * @return array|bool
+   */
   static function formRule($fields) {
     $errors = array();
     if (CRM_Utils_Array::value('monetaryThousandSeparator', $fields) ==
@@ -223,7 +202,7 @@ class CRM_Admin_Form_Setting_Localization extends CRM_Admin_Form_Setting {
 
     // CRM-7962, CRM-7713, CRM-9004
     if (!empty($fields['defaultContactCountry']) &&
-      (CRM_Utils_Array::value('countryLimit', $fields) &&
+      (!empty($fields['countryLimit']) &&
         (!in_array($fields['defaultContactCountry'], $fields['countryLimit']))
       )
     ) {
@@ -304,12 +283,12 @@ class CRM_Admin_Form_Setting_Localization extends CRM_Admin_Form_Setting {
     unset($values['currencyLimit']);
 
     // make the site multi-lang if requested
-    if (CRM_Utils_Array::value('makeMultilingual', $values)) {
+    if (!empty($values['makeMultilingual'])) {
       CRM_Core_I18n_Schema::makeMultilingual($values['lcMessages']);
       $values['languageLimit'][$values['lcMessages']] = 1;
       // make the site single-lang if requested
     }
-    elseif (CRM_Utils_Array::value('makeSinglelingual', $values)) {
+    elseif (!empty($values['makeSinglelingual'])) {
       CRM_Core_I18n_Schema::makeSinglelingual($values['lcMessages']);
       $values['languageLimit'] = '';
     }