CRM-15172 - Fix profile state/county required options
authorColeman Watts <coleman@civicrm.org>
Mon, 25 Aug 2014 20:08:39 +0000 (21:08 +0100)
committerColeman Watts <coleman@civicrm.org>
Mon, 25 Aug 2014 20:08:39 +0000 (21:08 +0100)
CRM/Core/BAO/UFGroup.php

index e26683a53bffdedf75704a8e294bd7dadf551f65..fb3849b83209f03e9a321576dfc4b15fb0b4e60b 100644 (file)
@@ -1831,11 +1831,12 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
     if (substr($fieldName, 0, 14) === 'state_province') {
       $controlField = str_replace('state_province', 'country', $name);
       if (isset($form->_fields[$controlField]) || in_array($controlField, $fieldsProcessed)) {
-        $form->addChainSelect($name, array('label' => $title, 'required' => $required));
+          $form->addChainSelect($name, array('label' => $title, 'required' => $required));
       }
       else {
+        $options = CRM_Core_PseudoConstant::stateProvince();
         $form->add('select', $name, $title,
-          array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required);
+          array('' => ts('- select -')) + $options, $required && $options);
       }
       $config = CRM_Core_Config::singleton();
       if (!in_array($mode, array(
@@ -1859,7 +1860,15 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
     }
     elseif (substr($fieldName, 0, 6) === 'county') {
       if ($addressOptions['county']) {
-        $form->addChainSelect($name, array('label' => $title, 'required' => $required));
+        $controlField = str_replace('county', 'state_province', $name);
+        if (isset($form->_fields[$controlField]) || in_array($controlField, $fieldsProcessed)) {
+          $form->addChainSelect($name, array('label' => $title, 'required' => $required));
+        }
+        else {
+          $options = CRM_Core_PseudoConstant::county();
+          $form->add('select', $name, $title,
+            array('' => ts('- select -')) + $options, $required && $options);
+        }
       }
     }
     elseif (substr($fieldName, 0, 9) === 'image_URL') {