Merge pull request #3617 from eileenmcnaughton/CRM-14946
[civicrm-core.git] / CRM / Contact / Form / Domain.php
index 4019aeaa0d7bf0a11e7f7c0f2ae0dc6190c7ea01..b958f8fd27cb37dadc0fc748d739fc90bfeb68cb 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$
  *
  */
@@ -59,6 +59,13 @@ class CRM_Contact_Form_Domain extends CRM_Core_Form {
    */
   protected $_fromEmailId = NULL;
 
+  /**
+   * default location type fields
+   *
+   * @var array
+   */
+  protected $_locationDefaults = array();
+
   /**
    * how many locationBlocks should we display?
    *
@@ -88,12 +95,23 @@ class CRM_Contact_Form_Domain extends CRM_Core_Form {
    * the default values are retrieved from the database
    *
    * @access public
-   * @return None
+   * @return void
+   */
+  /**
+   * This virtual function is used to set the default values of
+   * various form elements
+   *
+   * access        public
+   *
+   * @return array reference to the array of default values
+   *
+   */
+  /**
+   * @return array
    */
   function setDefaultValues() {
     $defaults  = array();
     $params    = array();
-    $locParams = array();
 
     if (isset($this->_id)) {
       $params['id'] = $this->_id;
@@ -115,7 +133,7 @@ class CRM_Contact_Form_Domain extends CRM_Core_Form {
 
       unset($params['id']);
       $locParams = array('contact_id' => $domainDefaults['contact_id']);
-      $defaults = CRM_Core_BAO_Location::getValues($locParams);
+      $this->_locationDefaults = $defaults = CRM_Core_BAO_Location::getValues($locParams);
 
       $config = CRM_Core_Config::singleton();
       if (!isset($defaults['address'][1]['country_id'])) {
@@ -149,7 +167,7 @@ class CRM_Contact_Form_Domain extends CRM_Core_Form {
   /**
    * Function to actually build the form
    *
-   * @return None
+   * @return void
    * @access public
    */
   public function buildQuickForm() {
@@ -244,9 +262,27 @@ class CRM_Contact_Form_Domain extends CRM_Core_Form {
 
     $defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
 
-    $params['address'][1]['location_type_id'] = $defaultLocationType->id;
-    $params['phone'][1]['location_type_id'] = $defaultLocationType->id;
-    $params['email'][1]['location_type_id'] = $defaultLocationType->id;
+    if (isset($this->_locationDefaults['address'][1]['location_type_id'])) {
+      $params['address'][1]['location_type_id'] = $this->_locationDefaults['address'][1]['location_type_id'];
+    }
+    else {
+      $params['address'][1]['location_type_id'] = $defaultLocationType->id;
+    }
+
+    if (isset($this->_locationDefaults['phone'][1]['location_type_id'])) {
+      $params['phone'][1]['location_type_id'] = $this->_locationDefaults['phone'][1]['location_type_id'];
+    }
+    else {
+      $params['phone'][1]['location_type_id'] = $defaultLocationType->id;
+    }
+
+    if (isset($this->_locationDefaults['email'][1]['location_type_id'])) {
+      $params['email'][1]['location_type_id'] = $this->_locationDefaults['email'][1]['location_type_id'];
+    }
+    else {
+      $params['email'][1]['location_type_id'] = $defaultLocationType->id;
+    }
+
     $params += array('contact_id' => $this->_contactId);
     $contactParams = array (
       'sort_name'    => $domain->name,