// Normal update process will automatically create new address with submitted values
// 1. loop through entire submitted address array
- $skipFields = array('is_primary', 'location_type_id', 'is_billing', 'master_id');
+ $skipFields = array('is_primary', 'location_type_id', 'is_billing', 'master_id', 'update_current_employer');
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.
continue;
}
+ // Set update_current_employer checkbox value
+ $values['update_current_employer'] = !empty($values['update_current_employer']);
+
// 3. get the address details for master_id
$masterAddress = new CRM_Core_BAO_Address();
$masterAddress->id = CRM_Utils_Array::value('master_id', $values);
// Override the default profile links to add address form
$profileLinks = CRM_Contact_BAO_Contact::getEntityRefCreateLinks('shared_address');
- $form->addEntityRef("address[$blockId][master_contact_id]", ts('Share With'), array('create' => $profileLinks));
+ $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'));
}
}
$query = 'SELECT id, contact_id FROM civicrm_address WHERE master_id = %1';
$dao = CRM_Core_DAO::executeQuery($query, array(1 => array($addressId, 'Integer')));
+ // Default to TRUE if not set to maintain api backward compatibility.
+ $createRelationship = isset($params['update_current_employer']) ? $params['update_current_employer'] : TRUE;
+
// unset contact id
$skipFields = array('is_primary', 'location_type_id', 'is_billing', 'contact_id');
if (isset($params['master_id']) && !CRM_Utils_System::isNull($params['master_id'])) {
- // call the function to create a relationship for the new shared address
- self::processSharedAddressRelationship($params['master_id'], $params['contact_id']);
+ if ($createRelationship) {
+ // call the function to create a relationship for the new shared address
+ self::processSharedAddressRelationship($params['master_id'], $params['contact_id']);
+ }
}
else {
// else no new shares will be created, only update shared addresses
$addressDAO = new CRM_Core_DAO_Address();
while ($dao->fetch()) {
// call the function to update the relationship
- if (isset($params['master_id']) && !CRM_Utils_System::isNull($params['master_id'])) {
+ if ($createRelationship && isset($params['master_id']) && !CRM_Utils_System::isNull($params['master_id'])) {
self::processSharedAddressRelationship($params['master_id'], $dao->contact_id);
}
$addressDAO->copyValues($params);
<p>{ts}You can use an address belonging to an existing contact or create a new contact by selecting the desired contact type from the select field. If you link an individual's address to an organization, an employee-employer relationship will be automatically created. If you link an individual's address to a household, a household member relationship is created.{/ts}</p>
{/htxt}
+{htxt id="id-sharedAddress-updateRelationships-title"}
+ {ts}Update Employer{/ts}
+{/htxt}
+{htxt id="id-sharedAddress-updateRelationships"}
+<p>{ts}Set this organization as the current employer for this individual. Note: will disable any existing employer relationship for this individual.{/ts}</p>
+{/htxt}
+
{htxt id="id-communication_style-title"}
{ts}Communication Style{/ts}
{/htxt}
<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>
<div class="shared-address-list">
{if !empty($sharedAddresses.$blockId.shared_address_display)}
{foreach item='sa' from=$sharedAddresses.$blockId.shared_address_display.options}
<script type="text/javascript">
CRM.$(function($) {
var blockNo = {/literal}{$blockId}{literal},
+ contactType = {/literal}{$contactType|@json_encode}{literal},
+ $employerSection = $('#shared-address-' + blockNo + ' .shared-address-update-employer'),
$contentArea = $('#shared-address-' + blockNo + ' .shared-address-list'),
$masterElement = $('input[name="address[' + blockNo + '][master_id]"]');
$masterElement.val('');
if (!sharedContactId || isNaN(sharedContactId)) {
+ $employerSection.hide();
return;
}
+ var otherContactType = $el.select2('data').extra.contact_type;
+ $employerSection.toggle(contactType === 'Individual' && otherContactType === 'Organization');
+
$.post(CRM.url('civicrm/ajax/inline'), {
'contact_id': sharedContactId,
'type': 'method',
$this->callAPISuccess('relationship', 'getcount', array(
'contact_id_a' => $individualID,
'contact_id_b' => $this->_contactID,
- ));
+ ), 1);
+ }
+
+ /**
+ * Create an address with a master ID and relationship creation disabled.
+ */
+ public function testCreateAddressWithoutMasterRelationshipOrganization() {
+ $address = $this->callAPISuccess('address', 'create', $this->_params);
+ $individualID = $this->individualCreate();
+ $individualParams = array(
+ 'contact_id' => $individualID,
+ 'master_id' => $address['id'],
+ 'update_current_employer' => 0,
+ );
+ $this->callAPISuccess('address', 'create', array_merge($this->_params, $individualParams));
+ $this->callAPISuccess('relationship', 'getcount', array(
+ 'contact_id_a' => $individualID,
+ 'contact_id_b' => $this->_contactID,
+ ), 0);
}
/**