Last active
October 1, 2016 23:28
-
-
Save thlor/1585192d93412da4d5a5155ad62a4420 to your computer and use it in GitHub Desktop.
Why https://www.drupal.org/node/2640842 is not a good idea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // {custom_module}/src/Plugin/migrate/process/CustomFile.php Replace {custom_nodule} with your module's machine name | |
namespace Drupal\{custom_module}\Plugin\migrate\process; // Replace {custom_nodule} with your module's machine name | |
use Drupal\migrate\Plugin\MigrationInterface; | |
use Drupal\file\Plugin\migrate\process\d6\CckFile; | |
use Symfony\Component\DependencyInjection\ContainerInterface; | |
/** | |
* @MigrateProcessPlugin( | |
* id = "custom_file" | |
* ) | |
*/ | |
class CustomFile extends CckFile { | |
/** | |
* {@inheritdoc} | |
*/ | |
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) { | |
$migration_plugin_configuration = [ | |
'source' => ['fid'], | |
'migration' => 'custom_files', // Tthis is the only overriden line from CckFile | |
]; | |
return new static( | |
$configuration, | |
$plugin_id, | |
$plugin_definition, | |
$migration, | |
$container->get('plugin.manager.migrate.process')->createInstance('migration', $migration_plugin_configuration, $migration) | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# {custom_module}/config/install/migrate_plus.migration.custom_files.yml | |
# customized /core/modules/file/migration_templates/d6_file.yml | |
id: custom_files | |
label: Custom files | |
source: | |
plugin: d6_file | |
destination: | |
plugin: 'entity:file' | |
urlencode: true | |
source_path_property: filepath | |
process: | |
uid: # unlike in d6_file.yml, we want uids to default to 1. This is the main reason I created a custom file migration. | |
plugin: default_value | |
default_value: 1 | |
filename: filename | |
# fid: we omit it, let fid autoincrement; we don't need to keep fids from d6. Therefore we can't use the same fids as in D6. | |
# Because of this, we need to override the CckFile object and specify that d6 fids be mapped to the autoincremented fids | |
# created by this migration. | |
uri: | |
plugin: file_uri | |
source: | |
- filepath | |
- file_directory_path | |
- temp_directory_path | |
- is_public | |
filemime: filemime | |
filesize: filesize | |
status: status | |
changed: timestamp | |
template: null | |
migration_dependencies: | |
optional: | |
- d6_file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# {custom_module}/config/install/migrate_plus.migration.custom_node.yml | |
id: custom_node | |
label: Custom node | |
migration_dependencies: | |
required: | |
- custom_files | |
source: | |
plugin: d6_node | |
destination: | |
plugin: entity:node | |
process: | |
nid: nid | |
vid: vid | |
type: type | |
langcode: | |
plugin: default_value | |
default_value: en | |
title: title | |
created: created | |
changed: changed | |
promote: promote | |
sticky: sticky | |
field_example_file: | |
plugin: custom_file # Exactly same as d6_file, with the exeption that migration id mapping is based on the custom_file migration. | |
source: field_d6_source_file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment