From: Samuel Vanhove Date: Mon, 27 Jan 2020 15:33:30 +0000 (-0500) Subject: dev/core#1319 generalize the creation of relationship when creating an shared address... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=1e2c74e1791d3fa0b5607ec9286471a815ad04c9;p=civicrm-core.git dev/core#1319 generalize the creation of relationship when creating an shared address to make it work with household --- diff --git a/CRM/Contact/BAO/Contact/Utils.php b/CRM/Contact/BAO/Contact/Utils.php index 28f3802490..1527e0ac42 100644 --- a/CRM/Contact/BAO/Contact/Utils.php +++ b/CRM/Contact/BAO/Contact/Utils.php @@ -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(); diff --git a/CRM/Contact/Form/Edit/Address.php b/CRM/Contact/Form/Edit/Address.php index 8cc795e56a..8d83f06a87 100644 --- a/CRM/Contact/Form/Edit/Address.php +++ b/CRM/Contact/Form/Edit/Address.php @@ -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')); } } diff --git a/CRM/Core/BAO/Address.php b/CRM/Core/BAO/Address.php index af3dbd233d..e7fbb59201 100644 --- a/CRM/Core/BAO/Address.php +++ b/CRM/Core/BAO/Address.php @@ -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']; diff --git a/templates/CRM/Contact/Form/ShareAddress.tpl b/templates/CRM/Contact/Form/ShareAddress.tpl index 93c1c99a6b..6a5b6f9872 100644 --- a/templates/CRM/Contact/Form/ShareAddress.tpl +++ b/templates/CRM/Contact/Form/ShareAddress.tpl @@ -30,10 +30,10 @@
{$form.address.$blockId.master_contact_id.label} {$form.address.$blockId.master_contact_id.html} -