There should be a field handler to migrate the title field to the imagefield, which the d6 image_caption module used to create captions to image_field_caption.

Comments

tommeir’s picture

Subscribing...

anyone knows how to extend MigrateImageFieldHandler to support the caption parameter added by this module?

someguy9’s picture

Issue summary: View changes

I'm able to get the field I need from D6 but can't seem to map the field to the D7 caption field, an update on this would be nice

iStryker’s picture

I have no clue how to do this. Just opened a support request in the migration module issue. #2450955: Support for Image Caption Module D6-D7

ngocketit’s picture

Couldn't find a proper solution and I ended up having following piece of code:

class PhotoGalleryNodeMigration extends BaseNodeMigration {
  public function __construct(array $arguments) {
    $this->sourceFields['photo_caption'] = t('Caption of the photo image field');

    parent::__construct($arguments);

    ....

    $this->addFieldMapping('field_photos:file_class')
         ->defaultValue('MigrateFileFid');

    $this->addFieldMapping('field_photos:alt', 'field_photos:alt');
    $this->addFieldMapping('field_photos:title', 'field_:title');
    $this->addFieldMapping('field_photos:image_field_caption', 'photo_caption');
  }

  public function prepareRow($row) {
    // Always include this snippet, in case our parent class decides to ignore the row.
    if (parent::prepareRow($row) === FALSE) {
      return FALSE;
    }

    $row->photo_caption = array();
    foreach ($row->{'field_photos:description'} as $delta => $desc) {
      $row->photo_caption[$delta] = array(
        'value' => $desc,
        'format' => 'filtered_html',
      );
    }
  }

  public function complete($node, stdClass $row) {
    parent::complete($node, $row);

    if (isset($row->photo_caption)) {
      $full_node = node_load($node->nid);
      foreach ($full_node->field_photos as $langcode => $items) {
        foreach ($items as $delta => $data) {
          $full_node->field_photos[$langcode][$delta]['image_field_caption'] = $row->photo_caption[$delta];
        }
      }
      node_save($full_node);
    }
  }
}

In the complete() method, the node is freshly loaded and the image_field_caption property is assigned before the node gets saved again. Seems to work for me.

iStryker’s picture

Status: Active » Closed (outdated)

Closing all 7.x issues