It took me forever to find a solution to the problem of migrating multiple images into an image field designed to hold unlimited images. Here is what I did that worked for me:
//begin new multiple -- order matters.
$this->addFieldMapping('field_multiple_image','multipleimages')
->separator(',');
$this->addFieldMapping('field_multiple_image:file_class')
->defaultValue('MigrateFileUri');
$this->addFieldMapping('field_multiple_image:source_dir')->defaultValue('/home/youruser/public_html/media/profile_pics');
$this->addFieldMapping('field_multiple_image:destination_dir')->defaultValue('public://pictures');
$this->addFieldMapping('field_multiple_image:preserve_files')
->defaultValue(false);
$this->addFieldMapping('field_multiple_image:file_replace')
->defaultValue(MigrateFile::FILE_EXISTS_REUSE);
//END NEW MULTIPLE
And in the prepareRow:
//Note this: the multiple images row was a comma delimited string of image names
public function prepareRow($current_row) {
$result=explode(',',$current_row->multipleimages);
foreach($result as $row){
drush_print($row);
$current_row->field_multiple_image[] = $row;
}
}
Comments
Comment #1
mikeryan