Started discussing this on #1279778: Improve argument passing to fields

I'm trying to map both the location and the description to a multi-value file field.

This is working for me for multiple values:

  public function prepareRow($current_row)
  {
    $attachments = db_select('legacy_news_attachments','a')
                    ->fields('a', array('prid','location'))
                    ->condition('prid',$current_row->prid)
                    ->execute();
    $attachments_locations = array();
    foreach($attachments as $attachment)
    {
      $attachments_locations[] = $attachment->location;
    }

    $current_row->attachments_location = $attachments_locations;   
    return TRUE;
  }

This is working for me for the description and the location (but I don't know how to do this for multiple value fields)

$arguments = MigrateFileFieldHandler::arguments(NULL, 'file_copy', FILE_EXISTS_RENAME, NULL, NULL, NULL, array('source_field' => 'attachments_description'));
    $this->addFieldMapping('field_attachment', 'attachments_location')
         ->arguments($arguments);

Does anybody know how to do this?

Comments

mikeryan’s picture

Status: Active » Postponed (maintainer needs more info)

Per http://drupal.org/node/1005090#comment-4450746, you should be able to make attachments_location an array of JSON-encoded arrays, one per image being migrated. In migrate_example's wine.inc, see WineWineMigration::prepareRow() for an example.

Does this help?

puddyglum’s picture

Status: Fixed » Postponed (maintainer needs more info)

That's awesome, it worked great!
Added this feature to the documentation page Advanced field mappings

puddyglum’s picture

Status: Postponed (maintainer needs more info) » Fixed

Status: Postponed (maintainer needs more info) » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Sunflower’s picture

Hi Mike,
Does json-encoded arrays still work? I tried the wine.inc no luck. Any ideas what i am doing wrong? http://drupal.org/node/1943324