<commit_before><?php

/**
 * Fieldmetadata.Get API specification (optional)
 * This is used for documentation and validation.
 *
 * @param array $spec description of fields supported by this API call
 * @return void
 * @see http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
 */
function _civicrm_api3_fieldmetadata_get_spec(&$params) {
  $params['entity']['api.required'] = 1;
  $params['entity']['description'] = "The entity type for which field metadata is being fetched";
  $params['entity']['type'] = CRM_Utils_Type::T_STRING;

  $params['entity_params']['api.required'] = 1;
  $params['entity_params']['description'] = "Parameters that will be passed to the Fetcher and Normalizer to give those classes enough information to return the metadata required. This will usually include the entity id or name, or sub-action etc";
}


/**
 * Fieldmetadata.Get API
 *
 * @param array $params
 * @return array API result descriptor
 * @see civicrm_api3_create_success
 * @see civicrm_api3_create_error
 * @throws API_Exception
 */
function civicrm_api3_fieldmetadata_get($params) {
  //Wrap our code in a try/catch so that we can translate the
  //CRM_Core_Exception into an API_Exception because
  //that play nicer with the core api wrapper
  try {
    $fetcher = CRM_Fieldmetadata_Fetcher::getInstanceForEntity($params['entity']);
    $data = $fetcher->fetch($params['entity_params']);

    $normalizer = CRM_Fieldmetadata_Normalizer::getInstanceForEntity($params['entity']);
    $return = $normalizer->normalize($data, $params['entity_params']);

    return civicrm_api3_create_success($return, $params, 'Fieldmetadata', 'Get');

  } catch (Exception $e) {
    throw new API_Exception($e->getMessage(), $e->getCode());
  }
}<commit_msg>FIS-33: Updated get api call to take context into account<commit_after><?php

/**
 * Fieldmetadata.Get API specification (optional)
 * This is used for documentation and validation.
 *
 * @param array $spec description of fields supported by this API call
 * @return void
 * @see http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
 */
function _civicrm_api3_fieldmetadata_get_spec(&$params) {
  $params['entity']['api.required'] = 1;
  $params['entity']['description'] = "The entity type for which field metadata is being fetched";
  $params['entity']['type'] = CRM_Utils_Type::T_STRING;

  $params['entity_params']['api.required'] = 1;
  $params['entity_params']['description'] = "Parameters that will be passed to the Fetcher and Normalizer to give those classes enough information to return the metadata required. This will usually include the entity id or name, or sub-action etc";
}


/**
 * Fieldmetadata.Get API
 *
 * @param array $params
 * @return array API result descriptor
 * @see civicrm_api3_create_success
 * @see civicrm_api3_create_error
 * @throws API_Exception
 */
function civicrm_api3_fieldmetadata_get($params) {
  //Wrap our code in a try/catch so that we can translate the
  //CRM_Core_Exception into an API_Exception because
  //that play nicer with the core api wrapper
  try {
    //Create a Fetcher and call fetch
    $fetcher = CRM_Fieldmetadata_Fetcher::getInstanceForEntity($params['entity']);
    $data = $fetcher->fetch($params['entity_params']);

    //Create a Normalizer Instance for this entity, and normalize the data
    $normalizer = CRM_Fieldmetadata_Normalizer::getInstanceForEntity($params['entity']);
    $return = $normalizer->normalize($data, $params['entity_params']);

    //If a specific context is being requested, update the widget types
    $context = CRM_Utils_Array::value("context", $params, false);
    if($context) {
      $normalizer->setWidgetTypesByContext($return['fields'], $context);
    }

    return civicrm_api3_create_success($return, $params, 'Fieldmetadata', 'Get');

  } catch (Exception $e) {
    throw new API_Exception($e->getMessage(), $e->getCode());
  }
}
{'fraction_non_alphanumeric': 0.12416964741951968, 'fraction_numerical': 0.004087889626980072, 'mean_word_length': 5.126760563380282, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5903401', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1116, 'n_words': 334}