Commit 86cc10b6 authored by webchick's avatar webchick

Issue #2408165 by phenaproxima, miguelc303, quietone, eliza411, tim.plunkett,...

Issue #2408165 by phenaproxima, miguelc303, quietone, eliza411, tim.plunkett, bdone, benjy: Migration Files for Drupal 7  Blocks
parent 333977ed
...@@ -3,10 +3,10 @@ label: Blocks ...@@ -3,10 +3,10 @@ label: Blocks
migration_tags: migration_tags:
- Drupal 6 - Drupal 6
source: source:
plugin: d6_block plugin: block
process: process:
# Drupal 8 does not have a status but it doesn't matter; this is here to # Block status is not a thing in Drupal 8, so this is how we skip over
# skip disabled blocks. # disabled blocks.
status: status:
plugin: skip_on_empty plugin: skip_on_empty
method: row method: row
...@@ -50,15 +50,18 @@ process: ...@@ -50,15 +50,18 @@ process:
2: views_block:who_s_new-block_1 2: views_block:who_s_new-block_1
3: views_block:who_s_online-who_s_online_block 3: views_block:who_s_online-who_s_online_block
- -
plugin: d6_block_plugin_id plugin: block_plugin_id
-
plugin: skip_on_empty
method: row
theme: theme:
plugin: d6_block_theme plugin: block_theme
source: source:
- theme - theme
- default_theme - default_theme
- admin_theme - admin_theme
region: region:
plugin: d6_block_region plugin: block_region
source: source:
- region - region
- theme - theme
...@@ -74,17 +77,20 @@ process: ...@@ -74,17 +77,20 @@ process:
label: title label: title
weight: weight weight: weight
settings: settings:
plugin: d6_block_settings plugin: block_settings
source: source:
- '@plugin' - '@plugin'
- delta - delta
- settings - settings
visibility: visibility:
plugin: d6_block_visibility plugin: block_visibility
source: source:
- visibility
- pages - pages
- roles - roles
- visibility # If the block uses PHP visibility, don't migrate it unless the PHP module
# is enabled.
skip_php: true
destination: destination:
plugin: entity:block plugin: entity:block
migration_dependencies: migration_dependencies:
......
id: d7_block
label: Blocks
migration_tags:
- Drupal 7
source:
plugin: block
process:
# Block status is not a thing in Drupal 8, so this is how we skip over
# disabled blocks.
status:
plugin: skip_on_empty
method: row
source: status
id:
-
plugin: concat
source:
- theme
- module
- delta
delimiter: _
plugin:
-
plugin: static_map
bypass: true
source:
- module
- delta
map:
book:
navigation: book_navigation
comment:
recent: views_block:comments_recent-block_1
forum:
active: forum_active_block
new: forum_new_block
# locale:
# 0: language_block
node:
syndicate: node_syndicate_block
search:
form: search_form_block
statistics:
popular: statistics_popular_block
system:
main: system_main_block
'powered-by': system_powered_by_block
user:
login: user_login_block
# 1: system_menu_block:tools
new: views_block:who_s_new-block_1
online: views_block:who_s_online-who_s_online_block
-
plugin: block_plugin_id
-
plugin: skip_on_empty
method: row
theme:
plugin: block_theme
source:
- theme
- default_theme
- admin_theme
region:
plugin: block_region
source:
- region
- theme
- '@theme'
region_map:
left: sidebar_first
right: sidebar_second
sidebar_first: sidebar_first
sidebar_second: sidebar_second
help: help
header: header
footer: footer
label: title
weight: weight
settings:
plugin: block_settings
source:
- '@plugin'
- delta
- settings
visibility:
plugin: block_visibility
source:
- visibility
- pages
- roles
# If the block uses PHP visibility, don't migrate it unless the PHP module
# is enabled.
skip_php: true
destination:
plugin: entity:block
migration_dependencies:
optional:
- d7_custom_block
- d7_user_role
<?php
/**
* @file
* Contains \Drupal\block\Plugin\migrate\destination\EntityBlock.
*/
namespace Drupal\block\Plugin\migrate\destination;
use Drupal\migrate\Plugin\migrate\destination\EntityConfigBase;
use Drupal\migrate\Row;
/**
* @MigrateDestination(
* id = "entity:block"
* )
*/
class EntityBlock extends EntityConfigBase {
/**
* {@inheritdoc}
*/
protected function getEntityId(Row $row) {
// Try to find the block by its plugin ID and theme.
$properties = array(
'plugin' => $row->getDestinationProperty('plugin'),
'theme' => $row->getDestinationProperty('theme'),
);
$blocks = array_keys($this->storage->loadByProperties($properties));
return reset($blocks);
}
}
...@@ -2,34 +2,38 @@ ...@@ -2,34 +2,38 @@
/** /**
* @file * @file
* Contains \Drupal\block\Plugin\migrate\process\d6\BlockPluginId. * Contains \Drupal\block\Plugin\migrate\process\BlockPluginId.
*/ */
namespace Drupal\block\Plugin\migrate\process\d6; namespace Drupal\block\Plugin\migrate\process;
use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\Entity\MigrationInterface; use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\MigrateSkipRowException; use Drupal\migrate\Plugin\MigrateProcessInterface;
use Drupal\migrate\Plugin\MigratePluginManager;
use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row; use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
* @MigrateProcessPlugin( * @MigrateProcessPlugin(
* id = "d6_block_plugin_id" * id = "block_plugin_id"
* ) * )
*/ */
class BlockPluginId extends ProcessPluginBase implements ContainerFactoryPluginInterface { class BlockPluginId extends ProcessPluginBase implements ContainerFactoryPluginInterface {
/** /**
* @var \Drupal\migrate\Plugin\MigratePluginManager * The migration process plugin, configured for lookups in d6_custom_block
* and d7_custom_block.
*
* @var \Drupal\migrate\Plugin\MigrateProcessInterface
*/ */
protected $processPluginManager; protected $migrationPlugin;
/** /**
* The block_content entity storage handler.
*
* @var \Drupal\Core\Entity\EntityStorageInterface * @var \Drupal\Core\Entity\EntityStorageInterface
*/ */
protected $blockContentStorage; protected $blockContentStorage;
...@@ -37,11 +41,10 @@ class BlockPluginId extends ProcessPluginBase implements ContainerFactoryPluginI ...@@ -37,11 +41,10 @@ class BlockPluginId extends ProcessPluginBase implements ContainerFactoryPluginI
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function __construct(array $configuration, $plugin_id, array $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, MigratePluginManager $process_plugin_manager) { public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityStorageInterface $storage, MigrateProcessInterface $migration_plugin) {
parent::__construct($configuration, $plugin_id, $plugin_definition); parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->blockContentStorage = $storage; $this->blockContentStorage = $storage;
$this->migration = $migration; $this->migrationPlugin = $migration_plugin;
$this->processPluginManager = $process_plugin_manager;
} }
/** /**
...@@ -49,13 +52,18 @@ public function __construct(array $configuration, $plugin_id, array $plugin_defi ...@@ -49,13 +52,18 @@ public function __construct(array $configuration, $plugin_id, array $plugin_defi
*/ */
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) { public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
$entity_manager = $container->get('entity.manager'); $entity_manager = $container->get('entity.manager');
$migration_configuration = array(
'migration' => array(
'd6_custom_block',
'd7_custom_block',
),
);
return new static( return new static(
$configuration, $configuration,
$plugin_id, $plugin_id,
$plugin_definition, $plugin_definition,
$migration,
$entity_manager->getDefinition('block_content') ? $entity_manager->getStorage('block_content') : NULL, $entity_manager->getDefinition('block_content') ? $entity_manager->getStorage('block_content') : NULL,
$container->get('plugin.manager.migrate.process') $container->get('plugin.manager.migrate.process')->createInstance('migration', $migration_configuration, $migration)
); );
} }
...@@ -70,31 +78,28 @@ public function transform($value, MigrateExecutableInterface $migrate_executable ...@@ -70,31 +78,28 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
switch ($module) { switch ($module) {
case 'aggregator': case 'aggregator':
list($type, $id) = explode('-', $delta); list($type, $id) = explode('-', $delta);
if ($type == 'category') { if ($type == 'feed') {
// @TODO skip row. return 'aggregator_feed_block';
// throw new MigrateSkipRowException();
} }
$value = 'aggregator_feed_block';
break; break;
case 'menu': case 'menu':
$value = "system_menu_block:$delta"; return "system_menu_block:$delta";
break;
case 'block': case 'block':
if ($this->blockContentStorage) { if ($this->blockContentStorage) {
$block_ids = $this->processPluginManager $block_id = $this->migrationPlugin
->createInstance('migration', array('migration' => 'd6_custom_block'), $this->migration)
->transform($delta, $migrate_executable, $row, $destination_property); ->transform($delta, $migrate_executable, $row, $destination_property);
$value = 'block_content:' . $this->blockContentStorage->load($block_ids[0])->uuid(); if ($block_id) {
} return 'block_content:' . $this->blockContentStorage->load($block_id)->uuid();
else { }
throw new MigrateSkipRowException();
} }
break; break;
default: default:
throw new MigrateSkipRowException(); break;
} }
} }
return $value; else {
return $value;
}
} }
} }
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
/** /**
* @file * @file
* Contains \Drupal\block\Plugin\migrate\process\d6\BlockRegion. * Contains \Drupal\block\Plugin\migrate\process\BlockRegion.
*/ */
namespace Drupal\block\Plugin\migrate\process\d6; namespace Drupal\block\Plugin\migrate\process;
use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\ProcessPluginBase;
...@@ -13,10 +13,11 @@ ...@@ -13,10 +13,11 @@
/** /**
* @MigrateProcessPlugin( * @MigrateProcessPlugin(
* id = "d6_block_region" * id = "block_region"
* ) * )
*/ */
class BlockRegion extends ProcessPluginBase { class BlockRegion extends ProcessPluginBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
* *
......
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
/** /**
* @file * @file
* Contains \Drupal\block\Plugin\migrate\process\d6\BlockSettings. * Contains \Drupal\block\Plugin\migrate\process\BlockSettings.
*/ */
namespace Drupal\block\Plugin\migrate\process\d6; namespace Drupal\block\Plugin\migrate\process;
use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\ProcessPluginBase;
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
/** /**
* @MigrateProcessPlugin( * @MigrateProcessPlugin(
* id = "d6_block_settings" * id = "block_settings"
* ) * )
*/ */
class BlockSettings extends ProcessPluginBase { class BlockSettings extends ProcessPluginBase {
......
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
/** /**
* @file * @file
* Contains \Drupal\block\Plugin\migrate\process\d6\BlockTheme. * Contains \Drupal\block\Plugin\migrate\process\BlockTheme.
*/ */
namespace Drupal\block\Plugin\migrate\process\d6; namespace Drupal\block\Plugin\migrate\process;
use Drupal\migrate\Entity\MigrationInterface; use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\MigrateExecutableInterface;
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
/** /**
* @MigrateProcessPlugin( * @MigrateProcessPlugin(
* id = "d6_block_theme" * id = "block_theme"
* ) * )
*/ */
class BlockTheme extends ProcessPluginBase implements ContainerFactoryPluginInterface { class BlockTheme extends ProcessPluginBase implements ContainerFactoryPluginInterface {
...@@ -74,11 +74,9 @@ public static function create(ContainerInterface $container, array $configuratio ...@@ -74,11 +74,9 @@ public static function create(ContainerInterface $container, array $configuratio
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* Set the block theme, based on the current default theme.
*/ */
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
list($theme, $d6_default_theme, $d6_admin_theme) = $value; list($theme, $default_theme, $admin_theme) = $value;
// If the source theme exists on the destination, we're good. // If the source theme exists on the destination, we're good.
if (isset($this->themes[$theme])) { if (isset($this->themes[$theme])) {
...@@ -87,13 +85,13 @@ public function transform($value, MigrateExecutableInterface $migrate_executable ...@@ -87,13 +85,13 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
// If the source block is assigned to a region in the source default theme, // If the source block is assigned to a region in the source default theme,
// then assign it to the destination default theme. // then assign it to the destination default theme.
if (strtolower($theme) == strtolower($d6_default_theme)) { if (strtolower($theme) == strtolower($default_theme)) {
return $this->themeConfig->get('default'); return $this->themeConfig->get('default');
} }
// If the source block is assigned to a region in the source admin theme, // If the source block is assigned to a region in the source admin theme,
// then assign it to the destination admin theme. // then assign it to the destination admin theme.
if (strtolower($theme) == strtolower($d6_admin_theme)) { if (strtolower($theme) == strtolower($admin_theme)) {
return $this->themeConfig->get('admin'); return $this->themeConfig->get('admin');
} }
......
...@@ -2,77 +2,140 @@ ...@@ -2,77 +2,140 @@
/** /**
* @file * @file
* Contains \Drupal\block\Plugin\migrate\process\d6\BlockVisibility. * Contains \Drupal\block\Plugin\migrate\process\BlockVisibility.
*/ */
namespace Drupal\block\Plugin\migrate\process\d6; namespace Drupal\block\Plugin\migrate\process;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\MigrateSkipRowException;
use Drupal\migrate\Plugin\MigrateProcessInterface;
use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row; use Drupal\migrate\Row;
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\Plugin\MigrateProcessInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
* @MigrateProcessPlugin( * @MigrateProcessPlugin(
* id = "d6_block_visibility" * id = "block_visibility"
* ) * )
*/ */
class BlockVisibility extends ProcessPluginBase implements ContainerFactoryPluginInterface { class BlockVisibility extends ProcessPluginBase implements ContainerFactoryPluginInterface {
/** /**
* The migration plugin. * The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The migration process plugin, configured for lookups in the d6_user_role
* and d7_user_role migrations.
* *
* @var \Drupal\migrate\Plugin\MigrateProcessInterface * @var \Drupal\migrate\Plugin\MigrateProcessInterface
*/ */
protected $migrationPlugin; protected $migrationPlugin;
/**
* Whether or not to skip blocks that use PHP for visibility. Only applies
* if the PHP module is not enabled.
*
* @var bool
*/
protected $skipPHP = FALSE;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, MigrateProcessInterface $migration_plugin) { public function __construct(array $configuration, $plugin_id, $plugin_definition, ModuleHandlerInterface $module_handler, MigrateProcessInterface $migration_plugin) {
parent::__construct($configuration, $plugin_id, $plugin_definition); parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->migration = $migration; $this->moduleHandler = $module_handler;
$this->migrationPlugin = $migration_plugin; $this->migrationPlugin = $migration_plugin;
if (isset($configuration['skip_php'])) {
$this->skipPHP = $configuration['skip_php'];
}
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) { public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
$migration_configuration = array(
'migration' => array(
'd6_user_role',
'd7_user_role',
),
);
return new static( return new static(
$configuration, $configuration,
$plugin_id, $plugin_id,
$plugin_definition, $plugin_definition,
$migration, $container->get('module_handler'),
$container->get('plugin.manager.migrate.process')->createInstance('migration', array('migration' => 'd6_user_role'), $migration) $container->get('plugin.manager.migrate.process')->createInstance('migration', $migration_configuration, $migration)
); );
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* Set the block visibility settings.
*/ */
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
list($pages, $roles, $old_visibility) = $value; list($old_visibility, $pages, $roles) = $value;
$visibility = array(); $visibility = array();
if (!empty($pages)) { // If the block is assigned to specific roles, add the user_role condition.
$visibility['request_path']['pages'] = $pages; if ($roles) {
$visibility['request_path']['id'] = 'request_path'; $visibility['user_role'] = array(
$visibility['request_path']['negate'] = !$old_visibility; 'id' => 'user_role',
} 'roles' => array(),
'context_mapping' => array(
'user' => '@user.current_user_context:current_user',
),
'negate' => FALSE,
);
if (!empty($roles)) {
foreach ($roles as $key => $role_id) { foreach ($roles as $key => $role_id) {
$new_role = $this->migrationPlugin->transform($role_id, $migrate_executable, $row, $destination_property); $roles[$key] = $this->migrationPlugin->transform($role_id, $migrate_executable, $row, $destination_property);
$visibility['user_role']['roles'][$new_role] = $new_role; }
$visibility['user_role']['roles'] = array_combine($roles, $roles);
}
if ($pages) {
// 2 == BLOCK_VISIBILITY_PHP in Drupal 6 and 7.
if ($old_visibility == 2) {
// If the PHP module is present, migrate the visibility code unaltered.
if ($this->moduleHandler->moduleExists('php')) {
$visibility['php'] = array(
'id' => 'php',
// PHP code visibility could not be negated in Drupal 6 or 7.
'negate' => FALSE,
'php' => $pages,
);
}
// Skip the row if we're configured to. If not, we don't need to do
// anything else -- the block will simply have no PHP or request_path
// visibility configuration.
elseif ($this->skipPHP) {
throw new MigrateSkipRowException();
}