0

I would like to use features to import/export some content. The content type conains custom field of file, so I am using hook_uuid_node_features_export_render_alter(&$export, $node, $module){..} to add UUID of the file to the export.

function MODULE-NAME_uuid_node_features_export_render_alter(&$export, $node, $module){
        if($module == 'MODULE-NAME'){
        $field_instance = field_get_items('node', $node, 'field_elastic_slide');
        foreach($field_instance as $key => $instance){
            $file = file_load($instance['image']);
            $export->field_elastic_slide['und'][$key]['image'] = (array)$file;
            $file = file_load($instance['thumb_image']);
            $export->field_elastic_slide['und'][$key]['thumb_image'] = (array)$file;
        }
    }
}

This works well and the UUID along the other file info is written into the file ending .features.uuid_node.inc part of the export module. So far, so good.

When importing, i would like to use the UUID to look up the FID of file on the Drupal instance import taking place, so i am using:

function MODULE-NAME_uuid_node_features_rebuild_alter(&$node, $module){
    if($module == 'MODULE-NAME'){
        $field_instance = field_get_items('node', $node, 'field_elastic_slide');
        foreach($field_instance as $key => $instance){
            $uuid = $instance['image']['uuid'];
            // We have a uuid - we'll try to retrieve fid.
            $file = entity_uuid_load('file',$uuid);//attempt 1
            $slider_img = current($file);

            $fid = uuid_get_serial_id('file', 'fid', $uuid); //attempt 2

            // There is no local image.
            if (empty($fid)) {
                watchdog(WATCHDOG_NOTICE, 'Slider image with uuid: ' . $uuid.' was not found', WATCHDOG_ERROR);
            }
            $node->field_elastic_slide['und'][$key]['image'] = $fid;
...

This is not working. Where is the UUID<->FID Map stored for features? How to retrieve the FID at the time of importing(enabling the feature)? Any help is much appriciated

0

I guess i didn't know exactly how the export/import works...perhaps, i still do not, but here is my theory so far. When importing custom fields containing file, we have to save the file in the table file_managed by ourselves. The feature module will only do the work of importing files for the default field types(file, text,etc) and not for custom fields which is our case.

Here is quick write up http://margotskapacs.com/2014/03/make-custom-field-with-file-exportable-in-drupal-features/

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.