I succeed to import the Image data (Alt, and title) and it's working when there is only one image in the Image field, but when there is multiple images, it just skip the import of the entire node and return this error:
array_flip(): Can only flip STRING and INTEGER values! [error]
File /home/website/bigd7/includes/entity.inc, line 178
Here my code:
In the constructor:
$this->sourceFields['image_title'] = 'Image Title text extracted from data';
$this->sourceFields['image_alt'] = 'Image alt text extracted from data';
Then the mapping:
$this->addFieldMapping('field_image:alt', 'image_alt');
$this->addFieldMapping('field_image:title', 'image_title');
$this->addFieldMapping('field_image', 'field_main_image')
->sourceMigration('Files');
$this->addFieldMapping('field_image:file_class')
->defaultValue('MigrateFileFid');
$this->addFieldMapping('field_image:preserve_files')
->defaultValue(TRUE);//not working
$this->addFieldMapping('field_image:file_replace')->defaultValue('FILE_EXISTS_REUSE');//not working
And then in the prepareRow:
$row->image_description = array();
$row->image_alt = array();
$row->image_title = array();
$datas = $row->{'field_main_image:data'};
foreach ($datas as $data) {
$data = unserialize($data);
if(!empty($data['description']))
$row->image_description[] = $data['description'];
else
$row->image_description[] = "";
if(!empty($data['alt']))
$row->image_alt[] = $data['alt'];
else
$row->image_alt[] = "";
if(!empty($data['title']))
$row->image_title[] = $data['title'];
else
$row->image_title[] = "";
}
When I remove the Alt/Title mapping, it's just import multiple images without any error.
Can you see the bug?
Comments
Comment #1
mikeryanThere's nothing obviously wrong I can see, although it's unusual to map subfields before the main field, I would move the :alt and title: mappings later - this would break with earlier versions of Migrate, what version are you running?
Try printing $row at the end of prepareRow and make sure it looks right - in particular, that field_main_image, image_alt, and image_title are all arrays of strings and are all in sync with each other.
Comment #2
kobee commentedHere the version I use:
Migrate 7.x-2.5
Drupal-to-Drupal migration (migrate_d2d) 7.x-2.0+4-dev
Here the output of the var_dump($row):
Tried to push down the alt, but no success.
Anything else?
Comment #3
mikeryanPlease upgrade to at least the 2.6-beta1 version of the Migrate module and see if that works any better.
Comment #4
kobee commentedIt works!
Thanks.
BTW, when do you plan to release the Migrate2.6?
Comment #5
mikeryanThe beta will stay out there for a couple of weeks, then my plan is to put out a release candidate (unless no significant issues come up in the meantime, in which case I'll go directly to full release).