function FieldFile::transform

Same name in other branches
  1. 9 core/modules/file/src/Plugin/migrate/process/d6/FieldFile.php \Drupal\file\Plugin\migrate\process\d6\FieldFile::transform()
  2. 8.9.x core/modules/file/src/Plugin/migrate/process/d6/FieldFile.php \Drupal\file\Plugin\migrate\process\d6\FieldFile::transform()
  3. 11.x core/modules/file/src/Plugin/migrate/process/d6/FieldFile.php \Drupal\file\Plugin\migrate\process\d6\FieldFile::transform()

Overrides ProcessPluginBase::transform

File

core/modules/file/src/Plugin/migrate/process/d6/FieldFile.php, line 66

Class

FieldFile

Namespace

Drupal\file\Plugin\migrate\process\d6

Code

public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
    $options = unserialize($value['data']);
    // Try to look up the ID of the migrated file. If one cannot be found, it
    // means the file referenced by the current field item did not migrate for
    // some reason -- file migration is notoriously brittle -- and we do NOT
    // want to send invalid file references into the field system (it causes
    // fatal errors), so return an empty item instead.
    $lookup_result = $this->migrateLookup
        ->lookup('d6_file', [
        $value['fid'],
    ]);
    if ($lookup_result) {
        return [
            'target_id' => $lookup_result[0]['fid'],
            'display' => $value['list'],
            'description' => $options['description'] ?? '',
            'alt' => $options['alt'] ?? '',
            'title' => $options['title'] ?? '',
        ];
    }
    else {
        return [];
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.