I have a node migration as part of a D6->D8 migration, and for the image field in the node, I've done a separate files migration, and then in my node migration, I just refer to the files migration to get the destination fid and write that to the image field.
field_image:
plugin: iterator
source: field_thumbnail
process:
target_id:
plugin: migration
migration: file
source: fid
The problem I'm running into is the error listed in the title. This is the presave() function:
public function preSave() {
parent::preSave();
$width = $this->width;
$height = $this->height;
// Determine the dimensions if necessary.
if (empty($width) || empty($height)) {
$image = \Drupal::service('image.factory')->get($this->entity->getFileUri());
if ($image->isValid()) {
$this->width = $image->getWidth();
$this->height = $image->getHeight();
}
}
}
It seems like it's dying because there is no image for that node, because it's dying at this line:
$image = \Drupal::service('image.factory')->get($this->entity->getFileUri());
It works just fine when there is an image for the node. Shouldn't this be skipped if there is no image found in the files migration? Is there a config option in the .yml file I can use to avoid this error?
Thanks.
UPDATE: I found this docs page on the skip_on_empty process plugin, and implemented as suggested on that page:
field_image:
plugin: iterator
source: field_thumbnail
process:
target_id:
-
plugin: migration
migration: file
source: fid
-
plugin: skip_on_empty
method: row
but I still get the same error, more than likely because in the pipeline, it's already errored out before it gets to the skip_on_empty plugin. However, if I switch things around:
field_image:
plugin: iterator
source: field_thumbnail
process:
target_id:
-
plugin: skip_on_empty
method: row
-
plugin: migration
migration: file
source: fid
Then the entire blog node is skipped if there is no image. How can I just skip trying to migrate the image if there is none?