function uuid_features_file_field_export in UUID Features Integration 7
Handle exporting file fields.
7 calls to uuid_features_file_field_export()
- uuid_bean_features_export_render in includes/
uuid_bean.features.inc - Implements hook_features_export_render().
- uuid_commerce_product_features_export_render in includes/
uuid_commerce_product.features.inc - Implements hook_features_export_render().
- uuid_field_collection_features_export_render in includes/
uuid_field_collection.features.inc - Implements hook_features_export_render().
- uuid_fpp_features_export_render in includes/
uuid_fpp.features.inc - Implements hook_features_export_render().
- uuid_node_features_export_render in includes/
uuid_node.features.inc - Implements hook_features_export_render().
File
- ./
uuid_features.module, line 442 - UUID Features module allows to export data stored in the db by features.
Code
function uuid_features_file_field_export(&$export, $entity_type) {
list($entity_id, $revision_id, $export_bundle) = entity_extract_ids($entity_type, $export);
$fields = field_info_instances($entity_type, $export_bundle);
$supported_fields = array_map('trim', explode(',', variable_get('uuid_features_file_supported_fields', 'file, image')));
// Check what entity types are enabled for uuid features file export.
$bundles = array();
$entity_info = entity_get_info($entity_type);
foreach ($entity_info['bundles'] as $key => $value) {
if (variable_get("uuid_features_file_{$entity_type}_{$key}", FALSE)) {
$bundles[$key] = $key;
}
}
if (!in_array($export_bundle, $bundles)) {
foreach ($fields as $field_instance) {
$field =& $export->{$field_instance['field_name']};
$info = field_info_field($field_instance['field_name']);
// If this field should implement file import/export system but
// filefield exports are not enabled for this entity, just set the field
// to an empty array.
if (in_array($info['type'], $supported_fields)) {
$field = array();
}
}
}
else {
$export_mode = variable_get('uuid_features_file_mode', 'inline');
switch ($export_mode) {
case 'local':
$export_var = 'uuid_features_file_path';
break;
case 'packaged':
$export_var = 'uuid_features_packaged_file_path';
$file_list = array();
break;
case 'remote':
$export_var = 'uuid_features_file_url';
break;
default:
case 'inline':
$export_var = 'uuid_features_file_data';
break;
}
// Get all fields from this entity.
foreach ($fields as $field_instance) {
// Load field infos to check the type.
if (empty($field_instance['field_name'])) {
continue;
}
$field =& $export->{$field_instance['field_name']};
$info = field_info_field($field_instance['field_name']);
// Check if this field should implement file import/export system.
if (in_array($info['type'], $supported_fields)) {
// We need to loop into each language because i18n translation can build
// fields with different language than the node one.
foreach ($field as $language => $files) {
if (is_array($files)) {
foreach ($files as $i => $file) {
try {
$export_data = uuid_features_file_export($file, $export_mode);
} catch (Exception $e) {
// There was an error exporting the file - skip it.
drupal_set_message($e
->getMessage(), 'warning', FALSE);
continue;
}
// Build the field again, and remove fid to be sure that imported
// node will rebuild the file again, or keep an existing one with
// a different fid.
unset($field[$language][$i]['fid'], $field[$language][$i]['timestamp']);
$field[$language][$i][$export_var] = $export_data;
if ($export_mode == 'packaged') {
$file_list[$export_data] = array(
'file_path' => $file['uri'],
);
}
}
}
}
}
}
if ($export_mode == 'packaged') {
return $file_list;
}
}
}