Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This page contains useful snippets for working with Transport data.
Migrate upload module files to filefield
This code is for a Drupal 5 to Drupal 6 migration; it may need altering for D6-D6.
/**
* Implementation of hook_transport_TYPE_prefilter_alter() for node.
*
*/
function MYMODULE_transport_node_prefilter_alter($remote_entity) {
// Get the remote node object.
$remote_node = $remote_entity->entity;
// Migrate upload files to filefield files.
if (isset($remote_node->files) && count($remote_node->files)) {
$remote_node->field_YOUR_FILEFIELD = array();
foreach ($remote_node->files as $fid => $file) {
// Add in missing items that filefield has on a $node.
$file['uid'] = $remote_node->uid;
$file['status'] = 1;
$file['timestamp'] = $remote_node->created;
$file['data'] = NULL;
$remote_node->field_YOUR_FILEFIELD[] = $file;
}
}