Skip to content

Commit

Permalink
Merge pull request #12834 from pradpnayak/preRelHook
Browse files Browse the repository at this point in the history
Respect pre hook for relationship to alter id in $params
  • Loading branch information
eileenmcnaughton authored Feb 4, 2019
2 parents c038b19 + e355968 commit 2099e28
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions CRM/Contact/BAO/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,15 @@ public static function legacyCreateMultiple(&$params, $ids = array()) {
*
* @return CRM_Contact_BAO_Relationship
*/
public static function add(&$params, $ids = array(), $contactId = NULL) {
$relationshipId = CRM_Utils_Array::value('relationship', $ids, CRM_Utils_Array::value('id', $params));
public static function add($params, $ids = array(), $contactId = NULL) {
$params['id'] = CRM_Utils_Array::value('relationship', $ids, CRM_Utils_Array::value('id', $params));

$hook = 'create';
if ($relationshipId) {
if ($params['id']) {
$hook = 'edit';
}
//@todo hook are called from create and add - remove one
CRM_Utils_Hook::pre($hook, 'Relationship', $relationshipId, $params);
CRM_Utils_Hook::pre($hook, 'Relationship', $params['id'], $params);

$relationshipTypes = CRM_Utils_Array::value('relationship_type_id', $params);

Expand All @@ -306,7 +306,7 @@ public static function add(&$params, $ids = array(), $contactId = NULL) {
if ($type == 6) {
CRM_Contact_BAO_Household::updatePrimaryContact($params['contact_id_b'], $params['contact_id_a']);
}
if (!empty($relationshipId) && self::isCurrentEmployerNeedingToBeCleared($params, $relationshipId, $type)) {
if (!empty($params['id']) && self::isCurrentEmployerNeedingToBeCleared($params, $params['id'], $type)) {
CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($params['contact_id_a']);
}
$relationship = new CRM_Contact_BAO_Relationship();
Expand All @@ -316,7 +316,7 @@ public static function add(&$params, $ids = array(), $contactId = NULL) {
$relationship->contact_id_b = $params['contact_id_b'];
$relationship->contact_id_a = $params['contact_id_a'];
$relationship->relationship_type_id = $type;
$relationship->id = $relationshipId;
$relationship->id = $params['id'];

$dateFields = array('end_date', 'start_date');

Expand All @@ -332,7 +332,7 @@ public static function add(&$params, $ids = array(), $contactId = NULL) {
$relationship->$defaultField = $params[$defaultField];
}
}
elseif (!$relationshipId) {
elseif (empty($params['id'])) {
$relationship->$defaultField = $defaultValue;
}
}
Expand Down

0 comments on commit 2099e28

Please sign in to comment.