From 8e383c2f5cb1d8205d706eb687474d9f5f9c9d38 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Mon, 16 Apr 2018 16:33:38 +0100 Subject: [PATCH] CRM-21849: Load contactTypes in PHP, not JS --- CRM/Contact/Form/Relationship.php | 2 ++ templates/CRM/Contact/Form/Relationship.tpl | 27 +++------------------ 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/CRM/Contact/Form/Relationship.php b/CRM/Contact/Form/Relationship.php index f4d9a14781..9d61ef4864 100644 --- a/CRM/Contact/Form/Relationship.php +++ b/CRM/Contact/Form/Relationship.php @@ -299,6 +299,8 @@ class CRM_Contact_Form_Relationship extends CRM_Core_Form { // Select list $relationshipList = CRM_Contact_BAO_Relationship::getContactRelationshipType($this->_contactId, $this->_rtype, $this->_relationshipId); + $this->assign('contactTypes', CRM_Contact_BAO_ContactType::contactTypeInfo(TRUE)); + foreach ($this->_allRelationshipNames as $id => $vals) { if ($vals['name_a_b'] === 'Employee of') { $this->assign('employmentRelationship', $id); diff --git a/templates/CRM/Contact/Form/Relationship.tpl b/templates/CRM/Contact/Form/Relationship.tpl index df3a0579ff..d66d3969a2 100644 --- a/templates/CRM/Contact/Form/Relationship.tpl +++ b/templates/CRM/Contact/Form/Relationship.tpl @@ -146,7 +146,7 @@ $form = $("form.{/literal}{$form.formClass}{literal}"), $relationshipTypeSelect = $('[name=relationship_type_id]', $form), relationshipData = {}, - contactTypes = {}; + contactTypes = {/literal}{$contactTypes|@json_encode}{literal}; (function init () { // Refresh options if relationship types were edited @@ -172,9 +172,7 @@ // reset relationshipData = {}; - return getContactTypes().then(function() { - return getRelationshipData(); - }); + return getRelationshipData(); } /** @@ -195,8 +193,8 @@ var subtype = relType["contact_subtype_" + suffix]; var type = subtype || relType["contact_type_" + suffix]; var label = getContactTypeLabel(type) || "Contact"; - var placeholder = "- select " + label.toLowerCase() + " -"; - relType["placeholder_" + suffix] = placeholder + label = label.toLowerCase(); + relType["placeholder_" + suffix] = "- select " + label + " -"; }); relationshipData[relType["id"]] = relType; @@ -225,23 +223,6 @@ return label; } - /** - * Fetches contact types - */ - function getContactTypes() { - var defer = $.Deferred(); - if ($.isEmptyObject(contactTypes)) { - CRM.api3("ContactType", "get").done(function (data) { - contactTypes = data.values; - defer.resolve(contactTypes); - }); - } else { - defer.resolve(contactTypes); - } - - return defer.promise(); - } - function updateSelect($select) { var val = $select.val(), -- 2.25.1