Skip to content
Snippets Groups Projects
Commit a126d042 authored by catch's avatar catch
Browse files

Issue #3091841 by quietone, Grevil, Anybody, mikelutz, smustgrave,...

Issue #3091841 by quietone, Grevil, Anybody, mikelutz, smustgrave, danflanagan8, jklmnop, ShaunDychko, fengtan, MariaIoann, ranjith_kumar_k_u: Remove hardcoded plugin IDs from migration process plugins
parent 757ca2c5
No related branches found
No related tags found
No related merge requests found
......@@ -22,6 +22,23 @@ process:
postfix: _
length: 29
source: module
_block_module_plugin_id:
-
plugin: static_map
source:
- module
map:
block: block
default_value: ''
-
plugin: skip_on_empty
method: process
-
plugin: migration_lookup
migration:
- d6_custom_block
source:
- delta
plugin:
-
plugin: static_map
......@@ -87,6 +104,9 @@ process:
- delta
- settings
- title
_role_ids:
plugin: roles_lookup
migration: d6_user_role
visibility:
plugin: block_visibility
source:
......
......@@ -25,6 +25,23 @@ process:
-
plugin: machine_name
field: id
_block_module_plugin_id:
-
plugin: static_map
source:
- module
map:
block: block
default_value: ''
-
plugin: skip_on_empty
method: process
-
plugin: migration_lookup
migration:
- d7_custom_block
source:
- delta
plugin:
-
plugin: static_map
......@@ -108,6 +125,9 @@ process:
- delta
- settings
- title
_role_ids:
plugin: roles_lookup
migration: d7_user_role
visibility:
plugin: block_visibility
source:
......
......@@ -88,9 +88,16 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
case 'block':
if ($this->blockContentStorage) {
$lookup_result = $this->migrateLookup->lookup(['d6_custom_block', 'd7_custom_block'], [$delta]);
if ($lookup_result) {
$block_id = $lookup_result[0]['id'];
$block_id = $row->getDestinationProperty('_block_module_plugin_id');
// Legacy generated migrations will not have the destination
// property '_block_module_plugin_id'.
if (!$block_id) {
$lookup_result = $this->migrateLookup->lookup(['d6_custom_block', 'd7_custom_block'], [$delta]);
if ($lookup_result) {
$block_id = $lookup_result[0]['id'];
}
}
if ($block_id) {
return 'block_content:' . $this->blockContentStorage->load($block_id)->uuid();
}
}
......
......@@ -97,13 +97,22 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
],
'negate' => FALSE,
];
// Legacy generated migrations will not have the destination property
// '_role_ids'.
$role_ids = $row->getDestinationProperty('_role_ids');
foreach ($roles as $key => $role_id) {
$lookup_result = $this->migrateLookup->lookup(['d6_user_role', 'd7_user_role'], [$role_id]);
if (!$role_ids) {
$lookup = $this->migrateLookup->lookup(['d6_user_role', 'd7_user_role'], [$role_id]);
$lookup_result = $lookup[0]['id'];
}
else {
$lookup_result = $role_ids[$role_id] ?? NULL;
}
if ($lookup_result) {
$roles[$key] = $lookup_result[0]['id'];
$roles[$key] = $lookup_result;
}
}
$visibility['user_role']['roles'] = array_combine($roles, $roles);
}
......
<?php
namespace Drupal\block\Plugin\migrate\process;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\MigrateLookupInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Gets the destination roles ID for an array of source roles IDs.
*
* The roles_lookup plugin is used to get the destination roles for roles that
* are assigned to a block. It always uses the 'roles' value on the row as the
* source value.
*
* Examples
*
* @code
* process:
* roles:
* plugin: roles_lookup
* migration: d7_user_role
* @endcode
*
* This will get the destination role ID for each role in the 'roles' value on
* the source row.
*
* @see \Drupal\migrate\Plugin\MigrateProcessInterface
*
* @MigrateProcessPlugin(
* id = "roles_lookup"
* )
*/
class RolesLookup extends ProcessPluginBase implements ContainerFactoryPluginInterface {
/**
* The migrate lookup service.
*
* @var \Drupal\migrate\MigrateLookupInterface
*/
protected $migrateLookup;
/**
* The migration for user role lookup.
*
* @var string
*/
protected $migration;
/**
* Constructs a BlockVisibility object.
*
* @param array $configuration
* The plugin configuration.
* @param string $plugin_id
* The plugin ID.
* @param mixed $plugin_definition
* The plugin definition.
* @param \Drupal\migrate\MigrateLookupInterface $migrate_lookup
* The migrate lookup service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrateLookupInterface $migrate_lookup) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->migrateLookup = $migrate_lookup;
if (isset($configuration['migration'])) {
$this->migration = $configuration['migration'];
}
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('migrate.lookup')
);
}
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$roles = $row->get('roles');
$roles_result = [];
// If the block is assigned to specific roles, add the user_role condition.
if ($roles) {
foreach ($roles as $role_id) {
$lookup_result = $this->migrateLookup->lookup([$this->migration], [$role_id]);
if ($lookup_result) {
$roles_result[$role_id] = $lookup_result[0]['id'];
}
}
}
return $roles_result;
}
}
......@@ -9,6 +9,7 @@ source:
plugin: d7_field_instance
constants:
status: true
comment_node: comment_node_
process:
type:
plugin: process_field
......@@ -25,6 +26,22 @@ process:
bypass: true
map:
comment_node_forum: comment_forum
_comment_type:
-
plugin: explode
source: bundle
delimiter: comment_node_
-
plugin: extract
index: [1]
default: false
-
plugin: skip_on_empty
method: process
-
plugin: migration_lookup
migration:
- d7_comment_type
bundle:
plugin: field_bundle
source:
......
......@@ -102,10 +102,15 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
// For comment entity types get the destination bundle from the
// d7_comment_type migration, if it exists.
if ($entity_type === 'comment' && $bundle != 'comment_forum') {
$value = str_replace('comment_node_', '', $bundle);
$migration = 'd7_comment_type';
$lookup_result = $this->migrateLookup->lookup($migration, [$value]);
$lookup_result = empty($lookup_result) ? NULL : reset($lookup_result[0]);
$lookup_result = $row->get('@_comment_type');
// Legacy generated migrations will not have the destination property
// '_comment_type'.
if (!$row->hasDestinationProperty('_comment_type')) {
$value = str_replace('comment_node_', '', $bundle);
$migration = 'd7_comment_type';
$lookup_result = $this->migrateLookup->lookup($migration, [$value]);
$lookup_result = empty($lookup_result) ? NULL : reset($lookup_result[0]);
}
}
return $lookup_result ? $lookup_result : $bundle;
}
......
......@@ -13,6 +13,27 @@
/**
* Migrate filter format serial to string id in permission name.
*
* The filter_format_permission plugin is used to get the filter formats for a
* role and convert it to a permission name.
*
* Available configuration keys:
* - migration: (optional) The filter migration. Defaults to
* 'd6_filter_format'.
*
* Examples:
*
* @code
* process:
* result:
* plugin: filter_format_permission
* migration: d6_filter_format
* @endcode
*
* This will use the 'd6_filter_format' migration to lookup the destination
* filter formats for a role.
*
* @see \Drupal\migrate\Plugin\MigrateProcessInterface
*
* @MigrateProcessPlugin(
* id = "filter_format_permission",
* handle_multiples = TRUE
......
......@@ -35,6 +35,7 @@ process:
- plugin: node_update_7008
- plugin: flatten
- plugin: filter_format_permission
migration: d6_filter_format
destination:
plugin: entity:user_role
migration_dependencies:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment