Merge pull request #15666 from revati90/shared_address
[civicrm-core.git] / api / v3 / Address.php
index ac1cb25e0701e09a9877a8d25b604e2173bf36f4..a9bd0e0c88f7be364632fd37edcbb0c23d6edd73 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 5                                                  |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2019                                |
+ | Copyright CiviCRM LLC (c) 2004-2020                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -42,7 +42,7 @@
  * @return array
  *   API result array
  */
-function civicrm_api3_address_create(&$params) {
+function civicrm_api3_address_create($params) {
   _civicrm_api3_check_edit_permissions('CRM_Core_BAO_Address', $params);
   /**
    * If street_parsing, street_address has to be parsed into
@@ -103,28 +103,32 @@ function civicrm_api3_address_create(&$params) {
 function _civicrm_api3_address_create_spec(&$params) {
   $params['location_type_id']['api.required'] = 1;
   $params['contact_id']['api.required'] = 1;
-  $params['street_parsing'] = array(
+  $params['street_parsing'] = [
     'title' => 'Street Address Parsing',
     'description' => 'Optional param to indicate you want the street_address field parsed into individual params',
     'type' => CRM_Utils_Type::T_BOOLEAN,
-  );
-  $params['skip_geocode'] = array(
+  ];
+  $params['skip_geocode'] = [
     'title' => 'Skip geocode',
     'description' => 'Optional param to indicate you want to skip geocoding (useful when importing a lot of addresses
       at once, the job \'Geocode and Parse Addresses\' can execute this task after the import)',
     'type' => CRM_Utils_Type::T_BOOLEAN,
-  );
-  $params['fix_address'] = array(
+  ];
+  $params['fix_address'] = [
     'title' => ts('Fix address'),
     'description' => ts('When true, apply various fixes to the address before insert. Default true.'),
     'type' => CRM_Utils_Type::T_BOOLEAN,
     'api.default' => TRUE,
-  );
-  $params['world_region'] = array(
+  ];
+  $params['world_region'] = [
     'title' => ts('World Region'),
     'name' => 'world_region',
     'type' => CRM_Utils_Type::T_TEXT,
-  );
+  ];
+  $defaultLocation = CRM_Core_BAO_LocationType::getDefault();
+  if ($defaultLocation) {
+    $params['location_type_id']['api.default'] = $defaultLocation->id;
+  }
 }
 
 /**
@@ -134,11 +138,11 @@ function _civicrm_api3_address_create_spec(&$params) {
  *   Array of parameters determined by getfields.
  */
 function _civicrm_api3_address_get_spec(&$params) {
-  $params['world_region'] = array(
+  $params['world_region'] = [
     'title' => ts('World Region'),
     'name' => 'world_region',
     'type' => CRM_Utils_Type::T_TEXT,
-  );
+  ];
 }
 
 /**
@@ -163,6 +167,6 @@ function civicrm_api3_address_delete($params) {
  * @return array
  *   API result array
  */
-function civicrm_api3_address_get(&$params) {
+function civicrm_api3_address_get($params) {
   return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, TRUE, 'Address');
 }