From b3ee84c91c79300ccc1ce0d3cbae83f5271e182f Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Wed, 21 Mar 2018 16:32:58 +0000 Subject: [PATCH] CRM-21849: Allow adding option_context to elements This is used when some extra parameters are required when refreshing option lists after inline editing, i.e. relationship types are limited to the current contact type --- CRM/Contact/Form/Relationship.php | 17 ++++++++++++++++- CRM/Core/Form.php | 6 ++++++ js/crm.optionEdit.js | 7 +++++-- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/CRM/Contact/Form/Relationship.php b/CRM/Contact/Form/Relationship.php index 3ef442ab9e..16932158ad 100644 --- a/CRM/Contact/Form/Relationship.php +++ b/CRM/Contact/Form/Relationship.php @@ -309,7 +309,22 @@ class CRM_Contact_Form_Relationship extends CRM_Core_Form { } } - $this->addField('relationship_type_id', array('options' => array('' => ts('- select -')) + $relationshipList, 'class' => 'huge', 'placeholder' => '- select -'), TRUE); + $this->addField( + 'relationship_type_id', + array( + 'options' => array('' => ts('- select -')) + $relationshipList, + 'class' => 'huge', + 'placeholder' => '- select -', + 'option_url' => 'civicrm/admin/reltype', + 'option_context' => array( + 'contact_id' => $this->_contactId, + 'relationship_direction' => $this->_rtype, + 'relationship_id' => $this->_relationshipId, + 'is_form' => TRUE, + ), + ), + TRUE + ); $label = $this->_action & CRM_Core_Action::ADD ? ts('Contact(s)') : ts('Contact'); $contactField = $this->addField('related_contact_id', array('label' => $label, 'name' => 'contact_id_b', 'multiple' => TRUE, 'create' => TRUE), TRUE); diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index 015b8390a7..d84189ee6e 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -408,6 +408,12 @@ class CRM_Core_Form extends HTML_QuickForm_Page { } } + // Add context for the editing of option groups + if (isset($extra['option_context'])) { + $context = json_encode($extra['option_context']); + $element->setAttribute('data-option-edit-context', $context); + } + return $element; } diff --git a/js/crm.optionEdit.js b/js/crm.optionEdit.js index 1b1338ce00..20e01b7afd 100644 --- a/js/crm.optionEdit.js +++ b/js/crm.optionEdit.js @@ -30,10 +30,13 @@ jQuery(function($) { */ function rebuildOptions($existing, rebuilder) { if ($existing.data('api-entity') && $existing.data('api-field')) { - CRM.api3($existing.data('api-entity'), 'getoptions', { + var params = { sequential: 1, field: $existing.data('api-field') - }) + }; + $.extend(params, $existing.data('option-edit-context')); + + CRM.api3($existing.data('api-entity'), 'getoptions', params) .done(function(data) { rebuilder($existing, data.values); }); -- 2.25.1