X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=api%2Fapi.php;h=7cbc5d180dcb56f88b29b805d538a6e4bcaaf1fc;hb=605ee23e6345365f3ca25da44568553e4b15d2b1;hp=224846279f99f02f2c089255cdbf9966b95b508e;hpb=499543c54101eabc3319eb09dffa38ed2782c4c9;p=civicrm-core.git diff --git a/api/api.php b/api/api.php index 224846279f..7cbc5d180d 100644 --- a/api/api.php +++ b/api/api.php @@ -15,12 +15,11 @@ * create, get, delete or some special action name. * @param array $params * array to be passed to function - * @param null $extra * * @return array|int */ -function civicrm_api(string $entity = NULL, string $action, array $params, $extra = NULL) { - return \Civi::service('civi_api_kernel')->runSafe($entity, $action, $params, $extra); +function civicrm_api(string $entity, string $action, array $params) { + return \Civi::service('civi_api_kernel')->runSafe($entity, $action, $params); } /** @@ -33,12 +32,12 @@ function civicrm_api(string $entity = NULL, string $action, array $params, $extr * @see https://docs.civicrm.org/dev/en/latest/api/v4/usage/ * * @param string $entity Name of the CiviCRM entity to access. - * All entity names are capitalized CamelCase, e.g. "ContributionPage". - * Most entities correspond to a database table (e.g. "Contact" is the table "civicrm_contact"). - * For a complete list of available entities, call civicrm_api4('Entity', 'get'); + * All entity names are capitalized CamelCase, e.g. `ContributionPage`. + * Most entities correspond to a database table (e.g. `Contact` is the table `civicrm_contact`). + * For a complete list of available entities, call `civicrm_api4('Entity', 'get');` * * @param string $action The "verb" of the api call. - * For a complete list of actions for a given entity (e.g. Contact), call civicrm_api4('Contact', 'getActions'); + * For a complete list of actions for a given entity (e.g. `Contact`), call `civicrm_api4('Contact', 'getActions');` * * @param array $params An array of API input keyed by parameter name. * The easiest way to discover all available parameters is to visit the API Explorer on your CiviCRM site. @@ -47,18 +46,20 @@ function civicrm_api(string $entity = NULL, string $action, array $params, $extr * @param string|int|array $index Controls the Result array format. * By default the api Result contains a non-associative array of data. Passing an $index tells the api to * automatically reformat the array, depending on the variable type passed: - * - * - Integer: return a single result array; e.g. index = 0 will return the first result, 1 will return the second, and -1 will return the last. - * - String: index the results by a field value; e.g. index = "name" will return an associative array with the field 'name' as keys. - * - Non-associative array: return a single value from each result; e.g. index = ['title'] will return a non-associative array of strings - the 'title' field from each result. - * - Associative array: a combination of the previous two modes; e.g. index = ['name' => 'title'] will return an array of strings - the 'title' field keyed by the 'name' field. + * - **Integer:** return a single result array; + * e.g. `$index = 0` will return the first result, 1 will return the second, and -1 will return the last. + * - **String:** index the results by a field value; + * e.g. `$index = "name"` will return an associative array with the field 'name' as keys. + * - **Non-associative array:** return a single value from each result; + * e.g. `$index = ['title']` will return a non-associative array of strings - the 'title' field from each result. + * - **Associative array:** a combination of the previous two modes; + * e.g. `$index = ['name' => 'title']` will return an array of strings - the 'title' field keyed by the 'name' field. * * @return \Civi\Api4\Generic\Result * @throws \API_Exception * @throws \Civi\API\Exception\NotImplementedException */ function civicrm_api4(string $entity, string $action, array $params = [], $index = NULL) { - $apiCall = \Civi\Api4\Utils\ActionUtil::getAction($entity, $action); $indexField = $index && is_string($index) && !CRM_Utils_Rule::integer($index) ? $index : NULL; $removeIndexField = FALSE; @@ -67,10 +68,7 @@ function civicrm_api4(string $entity, string $action, array $params = [], $index $params['select'][] = $indexField; $removeIndexField = TRUE; } - foreach ($params as $name => $param) { - $setter = 'set' . ucfirst($name); - $apiCall->$setter($param); - } + $apiCall = \Civi\API\Request::create($entity, $action, ['version' => 4] + $params); if ($index && is_array($index)) { $indexCol = reset($index);