function file_entity_uuid_entity_features_export_render_alter in UUID Features Integration 7
Implements hook_uuid_entity_features_export_render_alter().
File
- includes/
modules/ file_entity.inc, line 49 - Hooks for uuid_features on behalf of the file_entity module.
Code
function file_entity_uuid_entity_features_export_render_alter($entity_type, &$export, &$entity, $module) {
list($entity_id, $revision_id, $export_bundle) = entity_extract_ids($entity_type, $entity);
// Handle referenced file entities in fields.
$supported_fields = array_map('trim', explode(',', variable_get('uuid_features_file_supported_fields', 'file, image')));
$enabled_types = variable_get('uuid_features_entity_file', FALSE);
$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($export->{$field_name})) {
continue;
}
// Ensure file entity is properly processed for the export.
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;
// Export as file entity or inline? Also check that there's an uuid
// on the file object - if not we're better off with the inline file
// handling.
if (!empty($enabled_types[$file_entity->type]) && !empty($file_entity->uuid)) {
$files_loaded = entity_uuid_load('file', array(
$file_entity->uuid,
), array(), TRUE);
// Ensure additional keys added to the field value are preserved
// but all the other properties are removed in favor of the uuid.
$file_export = array(
'file_uuid' => $file_entity->uuid,
) + array_diff_key($field_value, (array) reset($files_loaded));
}
else {
$file_entity_type = 'file';
$export_file_entity = clone $file_entity;
drupal_alter('uuid_entity_features_export_render', $file_entity_type, $export_file_entity, $file_entity, $module);
$file_export = (array) $export_file_entity;
}
$export->{$field_name}[$lang_code][$i] = $file_export;
}
}
}
}
}
// Handle file entities itself.
if ($entity_type == 'file') {
$info = entity_get_info($entity_type);
// Ensure we don't export a revision key.
if (!empty($info['entity keys']['revision']) && isset($export->{$info['entity keys']['revision']})) {
unset($export->{$info['entity keys']['revision']});
}
unset($export->created, $export->changed);
}
}