You are here

function civicrm_entity_views_data_alter in CiviCRM Entity 7.2

Same name and namespace in other branches
  1. 8.3 civicrm_entity.views.inc \civicrm_entity_views_data_alter()

Implements hook_views_data_alter().

File

./civicrm_entity.module, line 260

Code

function civicrm_entity_views_data_alter(&$data) {
  $civicrm_entity_types = civicrm_entity_get_supported_entity_info();
  $enabled_entities = _civicrm_entity_enabled_entities();
  foreach ($civicrm_entity_types as $civicrm_entity_type => $info) {
    if (!empty($enabled_entities[$civicrm_entity_type]) && !empty($data[$civicrm_entity_type])) {
      foreach ($data[$civicrm_entity_type] as $property => $prop_info) {

        // unset auto-generated custom field views handlers due to civicrm_entity entity metadata coming from API getfields call
        if (strpos($property, 'custom_') === 0) {
          $name_array = explode('_', $property);
          if (isset($name_array[1]) && is_numeric($name_array[1])) {
            unset($data[$civicrm_entity_type][$property]);
          }
        }
      }
    }
  }
  if (!empty($enabled_entities['civicrm_contribution_recur']) && !empty($data['civicrm_contribution_recur']['next_sched_contribution'])) {
    foreach ($data['civicrm_contribution_recur'] as $property => $property_data) {
      if (strpos($property, 'next_sched_contribution') === 0) {
        $property_name_components = explode('_', $property);
        if (!empty($property_name_components[3])) {
          $new_name = $property_name_components[0] . '_' . $property_name_components[1] . '_' . $property_name_components[2] . '_date_' . $property_name_components[3] . (!empty($property_name_components[4]) ? '_' . $property_name_components[4] : '');
        }
        else {
          $new_name = implode('_', $property_name_components) . '_date';
        }
        $data['civicrm_contribution_recur'][$new_name] = $data['civicrm_contribution_recur'][$property];
        unset($data['civicrm_contribution_recur'][$property]);
      }
    }
  }
}