3 namespace Drupal\file\Plugin\migrate\process\d6;
5 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
6 use Drupal\migrate\Plugin\MigrationInterface;
7 use Drupal\migrate\MigrateExecutableInterface;
8 use Drupal\migrate\Plugin\MigrateProcessInterface;
9 use Drupal\migrate\ProcessPluginBase;
10 use Drupal\migrate\Row;
11 use Symfony\Component\DependencyInjection\ContainerInterface;
14 * @MigrateProcessPlugin(
15 * id = "d6_field_file"
18 class FieldFile extends ProcessPluginBase implements ContainerFactoryPluginInterface {
21 * The migration process plugin, configured for lookups in d6_file.
23 * @var \Drupal\migrate\Plugin\MigrateProcessInterface
25 protected $migrationPlugin;
28 * Constructs a FieldFile plugin instance.
30 * @param array $configuration
31 * The plugin configuration.
32 * @param string $plugin_id
34 * @param mixed $plugin_definition
35 * The plugin definition.
36 * @param \Drupal\migrate\Plugin\MigrationInterface $migration
37 * The current migration.
38 * @param \Drupal\migrate\Plugin\MigrateProcessInterface $migration_plugin
39 * An instance of the 'migration' process plugin.
41 public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, MigrateProcessInterface $migration_plugin) {
42 parent::__construct($configuration, $plugin_id, $plugin_definition);
43 $this->migration = $migration;
44 $this->migrationPlugin = $migration_plugin;
50 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
51 // Configure the migration process plugin to look up migrated IDs from
52 // a d6 file migration.
53 $migration_plugin_configuration = $configuration + [
54 'migration' => 'd6_file',
63 $container->get('plugin.manager.migrate.process')->createInstance('migration', $migration_plugin_configuration, $migration)
70 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
71 $options = unserialize($value['data']);
73 // Try to look up the ID of the migrated file. If one cannot be found, it
74 // means the file referenced by the current field item did not migrate for
75 // some reason -- file migration is notoriously brittle -- and we do NOT
76 // want to send invalid file references into the field system (it causes
77 // fatals), so return an empty item instead.
78 if ($fid = $this->migrationPlugin->transform($value['fid'], $migrate_executable, $row, $destination_property)) {
81 'display' => $value['list'],
82 'description' => isset($options['description']) ? $options['description'] : '',
83 'alt' => isset($options['alt']) ? $options['alt'] : '',
84 'title' => isset($options['title']) ? $options['title'] : '',