You are here

function civicrm_entity_rules_data_info in CiviCRM Entity 7.2

Same name and namespace in other branches
  1. 7 civicrm_entity.rules.inc \civicrm_entity_rules_data_info()

Implements of hook_rules_data_type_info().

File

./civicrm_entity.rules.inc, line 11
Implement Drupal Rules integration for CiviCRM

Code

function civicrm_entity_rules_data_info() {
  if (!civicrm_initialize(TRUE)) {
    return;
  }
  module_load_include('module', 'civicrm_entity', 'civicrm_entity');
  $info = array();
  $entities = _civicrm_entity_enabled_entities();
  foreach ($entities as $drupal_entity => $civicrm_entity) {
    $info[$drupal_entity] = array(
      'label' => t('CiviCRM @entity', array(
        '@entity' => $civicrm_entity,
      )),
      // parent => 'civicrm_entity',
      'wrap' => TRUE,
      'group' => 'CiviCRM',
      // 'ui class' => 'RulesDataUIEntityExportable',
      'module' => 'civicrm',
    );
    $info[$drupal_entity]['property_info'] = _civicrm_entity_getproperties($civicrm_entity);

    // I don't think these are being 'kept'.
    $fields = civicrm_api($civicrm_entity, 'getfields', array(
      'version' => 3,
      'action' => 'create',
    ));
    foreach ($fields['values'] as $fieldname => $field_specs) {
      if (!empty($field_specs['type']) && $field_specs['type'] == 1) {

        // Type is empty for custom fields - we should sort that out
        // but skipping for now.
        if (CRM_Utils_Array::Value('FKClassName', $field_specs)) {
          $fks = _civicrm_entity_chained_fks();
          if (array_key_exists($field_specs['FKClassName'], $fks)) {
            $fks_entity = $fks[$field_specs['FKClassName']];
            $info[$drupal_entity]['property_info'][$fieldname] = array(
              'label' => empty($field_specs['title']) ? 'label not defined in CiviCRM schema' : $field_specs['title'],
              'type' => 'civicrm_' . $fks_entity,
            );
          }
        }
        if ($fieldname == 'entity_id') {
          $fks_entity = 'contact';
          $info[$drupal_entity]['property_info'][$fieldname] = array(
            'label' => empty($field_specs['title']) ? 'label not defined in CiviCRM schema' : $field_specs['title'],
            'type' => 'civicrm_' . $fks_entity,
          );
        }
        $info[$drupal_entity]['property_info'][$fieldname] = array(
          'label' => empty($field_specs['title']) ? 'label not defined in CiviCRM schema' : $field_specs['title'],
          'type' => 'integer',
        );
        if (!empty($field_specs['options'])) {
          $info[$drupal_entity]['property_info'][$fieldname]['type'] = 'list<integer>';
          $info[$drupal_entity]['property_info'][$fieldname]['options list'] = '_civicrm_entity_rules_attach_options';
          $info[$drupal_entity]['property_info'][$fieldname]['options data'] = $field_specs['options'];
        }
      }
    }
  }
  return $info;
}