You are here

function file_entity_uuid_entity_features_export_alter in UUID Features Integration 7

Implements hook_uuid_entity_features_export_alter().

File

includes/modules/file_entity.inc, line 11
Hooks for uuid_features on behalf of the file_entity module.

Code

function file_entity_uuid_entity_features_export_alter($entity_type, &$data, $entity, $module) {

  // Only alter pipe if the handling of files is enabled.
  $enabled_types = variable_get('uuid_features_entity_file', FALSE);
  $supported_fields = array_map('trim', explode(',', variable_get('uuid_features_file_supported_fields', 'file, image')));
  if ($entity_type == 'file' || empty($enabled_types) || empty($supported_fields)) {
    return;
  }
  list($entity_id, $revision_id, $export_bundle) = entity_extract_ids($entity_type, $entity);

  // Handle referenced file entities in fields and add dependencies where
  // possible.
  $bundles = variable_get('uuid_features_file_' . $entity_type, array());
  if (in_array($export_bundle, $bundles)) {
    $fields = field_info_instances($entity_type, $export_bundle);
    foreach ($fields as $field_name => $field_instance) {
      $field_info = field_info_field($field_name);
      if (!in_array($field_info['type'], $supported_fields) || empty($entity->{$field_name})) {
        continue;
      }

      // Add file entity dependencies.
      foreach ($entity->{$field_name} as $lang_code => $field_values) {
        foreach ($field_values as $i => $field_value) {
          if (!empty($field_value)) {
            $file_entity = (object) $field_value;
            if (!empty($enabled_types[$file_entity->type])) {
              $data['features']['uuid_file_entity'][$file_entity->uuid] = $file_entity->uuid;
            }
          }
        }
      }
    }
  }
}