From bb6f71170af311f97ffb10b28b0f193d81ead14a Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 28 Aug 2015 10:56:41 -0400 Subject: [PATCH] CRM-17080 - Smarty api cleanup --- CRM/Core/Smarty/plugins/function.crmAPI.php | 20 +++++++------------- templates/CRM/Admin/Form/Job.tpl | 4 ++-- templates/CRM/Admin/Page/APIExplorer.tpl | 2 +- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/CRM/Core/Smarty/plugins/function.crmAPI.php b/CRM/Core/Smarty/plugins/function.crmAPI.php index bd65a5a4bc..21d0a6c4ea 100644 --- a/CRM/Core/Smarty/plugins/function.crmAPI.php +++ b/CRM/Core/Smarty/plugins/function.crmAPI.php @@ -39,22 +39,16 @@ * @return string|void */ function smarty_function_crmAPI($params, &$smarty) { - if (!array_key_exists('action', $params)) { - $params['action'] = "get"; - } - if (!array_key_exists('sequential', $params)) { - $params['sequential'] = 1; - } if (!array_key_exists('entity', $params)) { $smarty->trigger_error("assign: missing 'entity' parameter"); return "crmAPI: missing 'entity' parameter"; } $errorScope = CRM_Core_TemporaryErrorScope::create(array('CRM_Utils_REST', 'fatal')); - $action = $params['action']; $entity = $params['entity']; - unset($params['entity']); - unset($params['method']); - unset($params['assign']); + $action = CRM_Utils_Array::value('action', $params, 'get'); + $params['sequential'] = CRM_Utils_Array::value('sequential', $params, 1); + $var = CRM_Utils_Array::value('var', $params); + CRM_Utils_Array::remove($params, 'entity', 'action', 'var'); $params['version'] = 3; require_once 'api/api.php'; $result = civicrm_api($entity, $action, $params); @@ -68,13 +62,13 @@ function smarty_function_crmAPI($params, &$smarty) { $smarty->trigger_error("{crmAPI} " . $result["error_message"]); } - if (!array_key_exists('var', $params)) { + if (!$var) { return json_encode($result); } if (!empty($params['json'])) { - $smarty->assign($params["var"], json_encode($result)); + $smarty->assign($var, json_encode($result)); } else { - $smarty->assign($params["var"], $result); + $smarty->assign($var, $result); } } diff --git a/templates/CRM/Admin/Form/Job.tpl b/templates/CRM/Admin/Form/Job.tpl index 1f1b360378..18f3736689 100644 --- a/templates/CRM/Admin/Form/Job.tpl +++ b/templates/CRM/Admin/Form/Job.tpl @@ -55,8 +55,8 @@

- + {crmAPI entity="Entity" var="entities"} {foreach from=$entities.values item=entity} {/foreach} diff --git a/templates/CRM/Admin/Page/APIExplorer.tpl b/templates/CRM/Admin/Page/APIExplorer.tpl index 03229c9ea1..4c034bfce8 100644 --- a/templates/CRM/Admin/Page/APIExplorer.tpl +++ b/templates/CRM/Admin/Page/APIExplorer.tpl @@ -162,7 +162,7 @@