You are here

function civicrm_entity_get_custom_fields in CiviCRM Entity 7

Same name and namespace in other branches
  1. 7.2 civicrm_entity.module \civicrm_entity_get_custom_fields()

Parameters

$entity:

1 call to civicrm_entity_get_custom_fields()
civicrm_entity_rules_action_entity_create_info_alter in ./civicrm_entity.module
Info alteration callback for the entity create action. Here we add a tonne of fields to civicrm entity create

File

./civicrm_entity.module, line 1044
Implement CiviCRM entities as a Drupal Entity.

Code

function civicrm_entity_get_custom_fields($entity, $types = array(
  'Integer' => 'integer',
  'String' => 'text',
  'Date' => 'date',
)) {
  if (!civicrm_initialize()) {
    return array();
  }
  $fields = civicrm_api3($entity, 'getfields', array(
    'action' => 'create',
    'getoptions' => TRUE,
  ));
  $fields = $fields['values'];
  foreach ($fields as $field_name => $field) {
    if (substr($field_name, 0, 7) != 'custom_' || !in_array($field['data_type'], array_keys($types))) {
      unset($fields[$field_name]);
    }
    else {
      $fields[$field_name]['type'] = $types[$field['data_type']];
    }
  }
  return $fields;
}