* @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);
$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);
}
}
<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}
<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}