I just became co-maintainer of Image Field Caption module. There are 2 support tickets in the module issue queue, relating to mapping the image title to caption text area of the image field. This is for a D6 to D7 upgrade. With D8 almost out, there will be a lot of sites upgrading from D6 to D7 then to D8. I was wondering if I can get some help with them...atleast steer me in the right direction so I can add support to the module.

Issues are:
main issue - #2101751: Cannot migrate d6 imagefield title to d7 image_field_caption
minor issue that is somewhat related - #2293497: "Undefined index" error with d6-d7 migrate

Comments

mikeryan’s picture

Status: Active » Postponed (maintainer needs more info)

I think you can extend MigrateImageFieldHandler, something like:

class ImageCaptionImageFieldHandler extends MigrateImageFieldHandler {
  public function fields($type, $instance, $migration = NULL) {
    $fields = parent::fields($type, $instance, $migration);
    $fields += array(
      'image_field_caption' => t('Subfield: String to be used as the caption value'),
    );
    return $fields;
  }
  protected function buildFieldArray($field_array, $arguments, $delta) {
    if (isset($arguments['image_field_caption'])) {
      if (is_array($arguments['image_field_caption'])) {
        $field_array['image_field_caption'] = $arguments['image_field_caption'][$delta];
      }
      else {
        $field_array['image_field_caption'] = $arguments['image_field_caption'];
      }
    }
    return $field_array;
  }
}

Is that helpful?

mikeryan’s picture

Oh, meant to note - both MigrateImageFieldHandler and your new field handler would be in play for image fields - you would want to go to /admin/content/migrate/configure and under Handlers disable MigrateImageFieldHandler in favor of your extended handler.

istryker’s picture

I will try this and get back to this issue.

mikeryan’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)
ngocketit’s picture

Doesn't seem to work for me. Following is the code:

class ImageCaptionImageFieldHandler extends MigrateImageFieldHandler {
  public function fields($type, $instance, $migration = NULL) {
    $fields = parent::fields($type, $instance, $migration);
    $fields += array(
      'image_field_caption' => t('Subfield: String to be used as the caption value'),
    );
    return $fields;
  }
  protected function buildFieldArray($field_array, $arguments, $delta) {
    if (isset($arguments['image_field_caption'])) {
      if (is_array($arguments['image_field_caption'])) {
        $field_array['image_field_caption'] = $arguments['image_field_caption'][$delta];
      }
      else {
        $field_array['image_field_caption'] = $arguments['image_field_caption'];
      }
    }
    return $field_array;
  }
}
class PhotoGalleryNodeMigration extends BaseNodeMigration {
  public function __construct(array $arguments) {
    $this->sourceFields['photo_caption'] = t('Caption of the photo image field');

    parent::__construct($arguments);

    // Migrate the alt & title & caption of the images.
    $this->addFieldMapping('field_photos:alt', 'field_photos:alt');
    $this->addFieldMapping('field_photos:title', 'field_photos:title');
    $this->addFieldMapping('field_photos:image_field_caption', 'photo_caption');
  }

  public function prepareRow($row) {
    if (parent::prepareRow($row) === FALSE) {
      return FALSE;
    }

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

The image caption gets NULL for both value & format.

ngocketit’s picture

This is specific to image_field_caption module and has nothing to do with exposing subfield in the field handler class. Please check: https://www.drupal.org/node/2101751#comment-11123751 for a solution. Btw, the code provided by @mikeryan needs to be updated a bit, like so:

class ImageCaptionImageFieldHandler extends MigrateImageFieldHandler {
  public function fields($type, $instance, $migration = NULL) {
    $fields = parent::fields($type, $instance, $migration);
    $fields += array(
      'image_field_caption' => t('Subfield: String to be used as the caption value'),
    );
    return $fields;
  }
  protected function buildFieldArray($field_array, $arguments, $delta) {
    $field_array = parent::buildFieldArray($field_array, $arguments, $delta);

    if (isset($arguments['image_field_caption'])) {
      if (is_array($arguments['image_field_caption'])) {
        $field_array['image_field_caption'] = $arguments['image_field_caption'][$delta];
      }
      else {
        $field_array['image_field_caption'] = $arguments['image_field_caption'];
      }
    }
    return $field_array;
  }
}

Otherwise, the 'alt' and 'title' won't be migrated.