You are here

public function CivicrmDataSourceHandler::mappingSourceFieldsAlter in CRM Core 7

Alter for source fields on the mapping form.

Overrides CRMCoreDataSourceHandler::mappingSourceFieldsAlter

File

modules/crm_core_data_import/plugins/source/CivicrmDataSourceHandler.inc, line 488

Class

CivicrmDataSourceHandler

Code

public function mappingSourceFieldsAlter(&$fields, $entity_type, $entity_bundle, $importer) {
  $source_fields = array(
    'default_value' => t('(provide value)'),
  );
  if (!empty($importer->source_settings['source_mapping'])) {
    $source_mapping = $importer->source_settings['source_mapping'];
    if ($entity_type == 'crm_core_contact' && !empty($source_mapping['CivicrmContactEntityType'])) {
      $mapping_values = $source_mapping['CivicrmContactEntityType'];
      $civicrm_entity_type = 'Contact';
    }
    if ($entity_type == 'crm_core_activity' && !empty($source_mapping['CivicrmActivityEntityType'])) {
      $mapping_values = $source_mapping['CivicrmActivityEntityType'];
      $civicrm_entity_type = 'Activity';
    }

    // Loop over source mapping to restrict available options.
    if (!empty($mapping_values) && !empty($civicrm_entity_type)) {
      foreach ($mapping_values as $value) {
        if ($value['destination_entity_existing'] == $entity_bundle && !empty($fields[$civicrm_entity_type . ':' . $value['source_entity']])) {
          $source_fields += array(
            $civicrm_entity_type . ':' . $value['source_entity'] => $fields[$civicrm_entity_type . ':' . $value['source_entity']],
          );
        }
      }
    }
  }

  // If there is not only default_value.
  if (count($source_fields) > 1) {
    $fields = $source_fields;
  }
}