dev/core#1319 generalize the creation of relationship when creating an shared address...
authorSamuel Vanhove <samuel@symbiotic.coop>
Mon, 27 Jan 2020 15:33:30 +0000 (10:33 -0500)
committerSamuel Vanhove <samuel@symbiotic.coop>
Mon, 27 Jan 2020 15:33:30 +0000 (10:33 -0500)
CRM/Contact/BAO/Contact/Utils.php
CRM/Contact/Form/Edit/Address.php
CRM/Core/BAO/Address.php
templates/CRM/Contact/Form/ShareAddress.tpl
tests/phpunit/api/v3/AddressTest.php

index 28f380249093a9fd91665141bfd39241fbda55bb..1527e0ac422e40efe486f29c771233c6f970fa2e 100644 (file)
@@ -788,7 +788,7 @@ INNER JOIN civicrm_contact contact_target ON ( contact_target.id = act.contact_i
     // Normal update process will automatically create new address with submitted values
 
     // 1. loop through entire submitted address array
-    $skipFields = ['is_primary', 'location_type_id', 'is_billing', 'master_id', 'update_current_employer'];
+    $skipFields = ['is_primary', 'location_type_id', 'is_billing', 'master_id', 'add_relationship'];
     foreach ($address as & $values) {
       // 2. check if "Use another contact's address" is checked, if not continue
       // Additionally, if master_id is set (address was shared), set master_id to empty value.
@@ -799,8 +799,8 @@ INNER JOIN civicrm_contact contact_target ON ( contact_target.id = act.contact_i
         continue;
       }
 
-      // Set update_current_employer checkbox value
-      $values['update_current_employer'] = !empty($values['update_current_employer']);
+      // Set add_relationship checkbox value
+      $values['add_relationship'] = !empty($values['add_relationship']);
 
       // 3. get the address details for master_id
       $masterAddress = new CRM_Core_BAO_Address();
index 8cc795e56a58641032734354de33b0050c5e6504..8d83f06a873811f60f5861f8dfecefc4ca8dd1e7 100644 (file)
@@ -170,7 +170,7 @@ class CRM_Contact_Form_Edit_Address {
       $form->addEntityRef("address[$blockId][master_contact_id]", ts('Share With'), ['create' => $profileLinks, 'api' => ['extra' => ['contact_type']]]);
 
       // do we want to update employer for shared address
-      $form->addElement('checkbox', "address[$blockId][update_current_employer]", NULL, ts('Set this organization as current employer'));
+      $form->addElement('checkbox', "address[$blockId][add_relationship]", NULL, ts('Create a relationship with this contact'));
     }
   }
 
index af3dbd233da196c559995eebd657617ca50f6bdd..e7fbb5920162d60e43770adfd0364490e446a234 100644 (file)
@@ -1039,8 +1039,15 @@ SELECT is_primary,
     $query = 'SELECT id, contact_id FROM civicrm_address WHERE master_id = %1';
     $dao = CRM_Core_DAO::executeQuery($query, [1 => [$addressId, 'Integer']]);
 
+    // legacy - for api backward compatibility
+    if (!isset($params['add_relationship'] && isset($params['update_current_employer']))) {
+      // warning
+      CRM_Core_Error::deprecatedFunctionWarning('update_current_employer is deprecated, use add_relationship instead');
+      $params['add_relationship'] = $params['update_current_employer'];
+    }
+
     // Default to TRUE if not set to maintain api backward compatibility.
-    $createRelationship = isset($params['update_current_employer']) ? $params['update_current_employer'] : TRUE;
+    $createRelationship = isset($params['add_relationship']) ? $params['add_relationship'] : TRUE;
 
     // unset contact id
     $skipFields = ['is_primary', 'location_type_id', 'is_billing', 'contact_id'];
index 93c1c99a6bc97e0eb2b7313319a28a49d58afb57..6a5b6f9872d7dc0f779d39777c1c2b5314a47a68 100644 (file)
     <div id="shared-address-{$blockId}" class="form-layout-compressed">
       {$form.address.$blockId.master_contact_id.label}
       {$form.address.$blockId.master_contact_id.html}
-      <div class="shared-address-update-employer" style="display: none;">
-        {$form.address.$blockId.update_current_employer.html}
-        {$form.address.$blockId.update_current_employer.label}
-        {help id="id-sharedAddress-updateRelationships" file="CRM/Contact/Form/Contact"}
+      <div class="shared-address-create-relationship" style="display: none;">
+        {$form.address.$blockId.add_relationship.html}
+        {$form.address.$blockId.add_relationship.label}
+        <div class="employer">{help id="id-sharedAddress-updateRelationships" file="CRM/Contact/Form/Contact"}</div>
       </div>
       <div class="shared-address-list">
         {if !empty($sharedAddresses.$blockId.shared_address_display)}
@@ -55,7 +55,8 @@
   CRM.$(function($) {
     var blockNo = {/literal}{$blockId}{literal},
       contactType = {/literal}{$contactType|@json_encode}{literal},
-      $employerSection = $('#shared-address-' + blockNo + ' .shared-address-update-employer'),
+      $addRelationshipSection = $('#shared-address-' + blockNo + ' .shared-address-add-relationship'),
+      $employerSection = $('#shared-address-' + blockNo + ' .shared-address-add-relationship .employer'),
       $contentArea = $('#shared-address-' + blockNo + ' .shared-address-list'),
       $masterElement = $('input[name="address[' + blockNo + '][master_id]"]');
 
 
       if (!sharedContactId || isNaN(sharedContactId)) {
         $employerSection.hide();
+        $addRelationshipSection.hide();
         return;
       }
 
       var otherContactType = $el.select2('data').extra.contact_type;
+      $addRelationshipSection.toggle(contactType === 'Individual' && (otherContactType === 'Organization' || otherContactType === 'Household'));
       $employerSection.toggle(contactType === 'Individual' && otherContactType === 'Organization');
 
       $.post(CRM.url('civicrm/ajax/inline'), {
index 7f61b3ce5dd923cbfea36128007a74681148a9bd..b52856aba9e52468e789ff593f542434021809fd 100644 (file)
@@ -199,7 +199,7 @@ class api_v3_AddressTest extends CiviUnitTestCase {
     $individualParams = [
       'contact_id' => $individualID,
       'master_id' => $address['id'],
-      'update_current_employer' => 0,
+      'add_relationship' => 0,
     ];
     $this->callAPISuccess('address', 'create', array_merge($this->_params, $individualParams));
     $this->callAPISuccess('relationship', 'getcount', [