CRM-17080 - Smarty api cleanup
authorColeman Watts <coleman@civicrm.org>
Fri, 28 Aug 2015 14:56:41 +0000 (10:56 -0400)
committerColeman Watts <coleman@civicrm.org>
Fri, 28 Aug 2015 14:56:41 +0000 (10:56 -0400)
CRM/Core/Smarty/plugins/function.crmAPI.php
templates/CRM/Admin/Form/Job.tpl
templates/CRM/Admin/Page/APIExplorer.tpl

index bd65a5a4bc3d10106b5c8e97baa4556a90828ca6..21d0a6c4ea02c9e3a985b2b33be1ff688e855bff 100644 (file)
  * @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);
   }
 }
index 1f1b360378ac9b2cf76a4fe580913c0b04c4b96c..18f37366892c3a8d934bbf6d2027bd294b40e137 100644 (file)
@@ -55,8 +55,8 @@
 
         <div id="fname"><br/>
         </div>
-        <select name="api_entity" type="text" id="api_entity" class="form-select required">
-          {crmAPI entity="Entity" action="get" var="entities" version=3}
+        <select name="api_entity" type="text" id="api_entity" class="crm-form-select required">
+          {crmAPI entity="Entity" var="entities"}
           {foreach from=$entities.values item=entity}
             <option value="{$entity}"{if $entity eq $form.api_entity.value} selected="selected"{/if}>{$entity}</option>
           {/foreach}
index 03229c9ea177aac2418b664158e0c20b77df6b85..4c034bfce8c55efd9567be134157278b44a3b646 100644 (file)
       <label for="api-entity">{ts}Entity{/ts}:</label>
       <select class="crm-form-select big required" id="api-entity" name="entity">
         <option value="" selected="selected">{ts}Choose{/ts}...</option>
-        {crmAPI entity="Entity" action="get" var="entities" version=3}
+        {crmAPI entity="Entity" var="entities"}
         {foreach from=$entities.values item=entity}
           <option value="{$entity}" {if !empty($entities.deprecated) && in_array($entity, $entities.deprecated)}class="strikethrough"{/if}>
             {$entity}