From 2a7984093d08268beaea43825597280a8b8a4197 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 24 Sep 2018 09:42:00 -0400 Subject: [PATCH] Further fix to permission fields on relationship form --- CRM/Contact/Form/Relationship.php | 19 +++++++++---------- templates/CRM/Contact/Form/Relationship.tpl | 4 ---- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/CRM/Contact/Form/Relationship.php b/CRM/Contact/Form/Relationship.php index 2ce6c062f0..73aae11201 100644 --- a/CRM/Contact/Form/Relationship.php +++ b/CRM/Contact/Form/Relationship.php @@ -227,7 +227,7 @@ class CRM_Contact_Form_Relationship extends CRM_Core_Form { $defaults['description'] = CRM_Utils_Array::value('description', $this->_values); $defaults['is_active'] = CRM_Utils_Array::value('is_active', $this->_values); - // The javascript on the form will swap these fields if it is a b_a relationship, so we compensate here + // The postprocess function will swap these fields if it is a b_a relationship, so we compensate here $defaults['is_permission_a_b'] = CRM_Utils_Array::value('is_permission_' . $this->_rtype, $this->_values); $defaults['is_permission_b_a'] = CRM_Utils_Array::value('is_permission_' . strrev($this->_rtype), $this->_values); @@ -584,17 +584,17 @@ class CRM_Contact_Form_Relationship extends CRM_Core_Form { */ private function preparePostProcessParameters($values) { $params = $values; - list($relationshipTypeId, $relationshipContactA, $relationshipContactB) = explode('_', $params['relationship_type_id']); + list($relationshipTypeId, $a, $b) = explode('_', $params['relationship_type_id']); $params['relationship_type_id'] = $relationshipTypeId; - $params['contact_id_' . $relationshipContactA] = $this->_contactId; + $params['contact_id_' . $a] = $this->_contactId; if (empty($this->_relationshipId)) { - $params['contact_id_' . $relationshipContactB] = explode(',', $params['related_contact_id']); + $params['contact_id_' . $b] = explode(',', $params['related_contact_id']); } else { $params['id'] = $this->_relationshipId; - $params['contact_id_' . $relationshipContactB] = $params['related_contact_id']; + $params['contact_id_' . $b] = $params['related_contact_id']; foreach (array('start_date', 'end_date') as $dateParam) { if (!empty($params[$dateParam])) { @@ -603,12 +603,11 @@ class CRM_Contact_Form_Relationship extends CRM_Core_Form { } } - // The javascript on the form will swap these fields if it is a b_a relationship, so we compensate here - $relationshipType = "${relationshipContactA}_${relationshipContactB}"; - $params['is_permission_a_b'] = CRM_Utils_Array::value('is_permission_' . $relationshipType, $values, 0); - $params['is_permission_b_a'] = CRM_Utils_Array::value('is_permission_' . strrev($relationshipType), $values, 0); + // If this is a b_a relationship these form elements are flipped + $params['is_permission_a_b'] = CRM_Utils_Array::value("is_permission_{$a}_{$b}", $values, 0); + $params['is_permission_b_a'] = CRM_Utils_Array::value("is_permission_{$b}_{$a}", $values, 0); - return array($params, $relationshipContactA); + return array($params, $a); } /** diff --git a/templates/CRM/Contact/Form/Relationship.tpl b/templates/CRM/Contact/Form/Relationship.tpl index 8165519e27..23239b69a4 100644 --- a/templates/CRM/Contact/Form/Relationship.tpl +++ b/templates/CRM/Contact/Form/Relationship.tpl @@ -262,10 +262,6 @@ // Show/hide employer field $('.crm-relationship-form-block-is_current_employer', $form).toggle(rType === {/literal}'{$employmentRelationship}'{literal}); - // Swap the permission checkboxes to match selected relationship direction - $('#is_permission_a_b', $form).attr('name', 'is_permission_' + source + '_' + target); - $('#is_permission_b_a', $form).attr('name', 'is_permission_' + target + '_' + source); - CRM.buildCustomData('Relationship', rType); } } -- 2.25.1