diff -u b/core/modules/block/migration_templates/d6_block.yml b/core/modules/block/migration_templates/d6_block.yml --- b/core/modules/block/migration_templates/d6_block.yml +++ b/core/modules/block/migration_templates/d6_block.yml @@ -79,13 +79,15 @@ - @plugin - delta - settings - visibility: + 'visibility/user_role': + plugin: block_visibility_role + source: roles + 'visibility/request_path': - - plugin: d6_block_visibility + plugin: block_visibility_pages source: - - pages - - roles - visibility + - pages - plugin: skip_on_empty method: process diff -u b/core/modules/block/src/Plugin/migrate/process/d6/BlockVisibility.php /dev/null --- b/core/modules/block/src/Plugin/migrate/process/d6/BlockVisibility.php +++ /dev/null @@ -1,115 +0,0 @@ -migration = $migration; - $this->migrationPlugin = $migration_plugin; - $this->moduleHandler = $module_handler; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $migration, - $container->get('plugin.manager.migrate.process')->createInstance('migration', array('migration' => 'd6_user_role'), $migration), - $container->get('module_handler') - ); - } - /** - * {@inheritdoc} - * - * Set the block visibility settings. - */ - public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { - list($pages, $roles, $old_visibility) = $value; - $visibility = array(); - - if (!empty($pages)) { - $visibility['request_path']['id'] = 'request_path'; - $visibility['request_path']['negate'] = !$old_visibility; - - // If the visibility was using PHP code, handle it separately. - if ($old_visibility == 2) { - // If the PHP module is installed, migrate the old data directly. - if ($this->moduleHandler->moduleExists('php')) { - $visibility['request_path']['pages'] = $pages; - } - else { - throw new MigrateException(); - } - } - // For non-PHP code, ensure paths have leading slashes. - else { - $paths = preg_split("(\r\n?|\n)", $pages); - foreach ($paths as $key => $path) { - $paths[$key] = $path === '' ? $path : '/' . ltrim($path, '/'); - } - $visibility['request_path']['pages'] = implode("\n", $paths); - } - } - - if (!empty($roles)) { - foreach ($roles as $key => $role_id) { - $new_role = $this->migrationPlugin->transform($role_id, $migrate_executable, $row, $destination_property); - $visibility['user_role']['roles'][$new_role] = $new_role; - } - $visibility['user_role']['id'] = 'user_role'; - $visibility['user_role']['context_mapping']['user'] = 'user.current_user'; - } - return $visibility; - } - -} diff -u b/core/modules/block/src/Tests/Migrate/d6/MigrateBlockTest.php b/core/modules/block/src/Tests/Migrate/d6/MigrateBlockTest.php --- b/core/modules/block/src/Tests/Migrate/d6/MigrateBlockTest.php +++ b/core/modules/block/src/Tests/Migrate/d6/MigrateBlockTest.php @@ -139,7 +139,6 @@ $visibility['request_path']['id'] = 'request_path'; $visibility['request_path']['negate'] = TRUE; $visibility['request_path']['pages'] = '/node/1'; - $this->assertEntity('system', $visibility, 'footer', 'bartik', -5); // Check menu blocks @@ -165,4 +164,4 @@ $this->assertFalse($block instanceof Block); - } + } reverted: --- b/core/modules/block/tests/src/Unit/Plugin/migrate/process/d6/BlockVisibilityTest.php +++ /dev/null @@ -1,142 +0,0 @@ -migration = $this->prophesize(MigrationInterface::class); - $this->migrationPlugin = $this->prophesize(MigrateProcessInterface::class); - $this->moduleHandler = $this->prophesize(ModuleHandlerInterface::class); - $this->plugin = new BlockVisibility([], 'map', array(), $this->migration->reveal(), $this->migrationPlugin->reveal(), $this->moduleHandler->reveal()); - } - - /** - * @covers ::transform - * - * @dataProvider providerTestTransform - */ - public function testTransform($pages, $roles, $visibility, $expected) { - $this->migrationPlugin->transform('2', $this->migrateExecutable, $this->row, 'destinationproperty')->willReturn('authenticated'); - $value = [$pages, $roles, $visibility]; - $transformed_value = $this->plugin->transform($value, $this->migrateExecutable, $this->row, 'destinationproperty'); - $this->assertSame($expected, $transformed_value); - } - - public function providerTestTransform() { - $data = []; - $data['no_data'] = [ - '', - [], - 0, - [], - ]; - $data['single_page_with_front'] = [ - '', - [], - 0, - ['request_path' => [ - 'id' => 'request_path', - 'negate' => TRUE, - 'pages' => '', - ]], - ]; - $data['multiple_pages_with_front'] = [ - "foo\n/bar\rbaz\r\n", - [], - 1, - ['request_path' => [ - 'id' => 'request_path', - 'negate' => FALSE, - 'pages' => "/foo\n/bar\n/baz\n", - ]], - ]; - $data['user_roles'] = [ - '', - ['2'], - 1, - ['user_role' => [ - 'roles' => [ - 'authenticated' => 'authenticated', - ], - 'id' => 'user_role', - 'context_mapping' => [ - 'user' => 'user.current_user', - ], - ]], - ]; - return $data; - } - - /** - * @covers ::transform - */ - public function testTransformPhpEnabled() { - $this->moduleHandler->moduleExists('php')->willReturn(TRUE); - - $pages = 'plugin->transform($value, $this->migrateExecutable, $this->row, 'destinationproperty'); - - $expected = ['request_path' => [ - 'id' => 'request_path', - 'negate' => FALSE, - 'pages' => $pages, - ]]; - $this->assertSame($expected, $transformed_value); - } - - /** - * @covers ::transform - * - * @expectedException \Drupal\migrate\MigrateException - */ - public function testTransformPhpDisabled() { - $value = ['plugin->transform($value, $this->migrateExecutable, $this->row, 'destinationproperty'); - - $expected = []; - $this->assertSame($expected, $transformed_value); - } - -} only in patch2: unchanged: --- /dev/null +++ b/core/modules/block/src/Plugin/migrate/process/BlockVisibilityPages.php @@ -0,0 +1,81 @@ +moduleHandler = $module_handler; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('module_handler') + ); + } + + /** + * {@inheritdoc} + */ + public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { + list($old_visibility, $pages) = $value; + $visibility = array(); + + if (!empty($pages)) { + // If the visibility was using PHP code, handle it separately. + if ($old_visibility == 2) { + // If the PHP module is installed, migrate the old data directly. + if ($this->moduleHandler->moduleExists('php')) { + $visibility['pages'] = $pages; + } + } + // For non-PHP code, ensure paths have leading slashes. + else { + $paths = preg_split("(\r\n?|\n)", $pages); + foreach ($paths as $key => $path) { + $paths[$key] = $path === '' ? $path : '/' . ltrim($path, '/'); + } + $visibility['pages'] = implode("\n", $paths); + } + } + + if ($visibility) { + return $visibility + ['id' => 'request_path', 'negate' => !$old_visibility]; + } + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/block/src/Plugin/migrate/process/BlockVisibilityRole.php @@ -0,0 +1,80 @@ +migrationPlugin = $migration_plugin; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('plugin.manager.migrate.process')->createInstance('migration', ['migration' => 'd6_user_role']) + ); + } + + /** + * {@inheritdoc} + */ + public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { + $visibility = array( + 'id' => 'user_role', + 'context_mapping' => array( + 'user' => 'user.current_user', + ), + ); + + foreach ($value as $key => $role_id) { + $new_role = $this->migrationPlugin->transform($role_id, $migrate_executable, $row, $destination_property); + $visibility['roles'][$new_role] = $new_role; + } + + return $visibility; + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/block/tests/src/Unit/Plugin/migrate/process/BlockVisibilityPagesTest.php @@ -0,0 +1,86 @@ +moduleHandler = $this->prophesize(ModuleHandlerInterface::class); + $this->plugin = new BlockVisibilityPages([], 'block_visibility_pages', [], $this->moduleHandler->reveal()); + } + + /** + * @covers ::transform + */ + public function testTransformNoData() { + $transformed_value = $this->plugin->transform([0, ''], $this->migrateExecutable, $this->row, 'destinationproperty'); + $this->assertNull($transformed_value); + } + + /** + * @covers ::transform + */ + public function testTransformSinglePageWithFront() { + $transformed_value = $this->plugin->transform([0, ''], $this->migrateExecutable, $this->row, 'destinationproperty'); + $this->assertSame('request_path', $transformed_value['id']); + $this->assertTrue($transformed_value['negate']); + $this->assertSame('', $transformed_value['pages']); + } + + /** + * @covers ::transform + */ + public function testTransformMultiplePagesWithFront() { + $transformed_value = $this->plugin->transform([1, "foo\n/bar\rbaz\r\n"], $this->migrateExecutable, $this->row, 'destinationproperty'); + $this->assertSame('request_path', $transformed_value['id']); + $this->assertFalse($transformed_value['negate']); + $this->assertSame("/foo\n/bar\n/baz\n", $transformed_value['pages']); + } + + /** + * @covers ::transform + */ + public function testTransformPhpEnabled() { + $this->moduleHandler->moduleExists('php')->willReturn(TRUE); + $transformed_value = $this->plugin->transform([2, 'migrateExecutable, $this->row, 'destinationproperty'); + $this->assertSame('request_path', $transformed_value['id']); + $this->assertFalse($transformed_value['negate']); + $this->assertSame('moduleHandler->moduleExists('php')->willReturn(FALSE); + $transformed_value = $this->plugin->transform([2, 'migrateExecutable, $this->row, 'destinationproperty'); + $this->assertEmpty($transformed_value); + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/block/tests/src/Unit/Plugin/migrate/process/BlockVisibilityRoleTest.php @@ -0,0 +1,50 @@ +migrationPlugin = $this->prophesize(MigrateProcessInterface::class); + $this->plugin = new BlockVisibilityRole([], 'block_visibility_role', [], $this->migrationPlugin->reveal()); + } + + /** + * @covers ::transform + */ + public function testTransform() { + $roles = [2]; + $this->migrationPlugin->transform('2', $this->migrateExecutable, $this->row, 'destinationproperty')->willReturn('authenticated'); + $transformed_value = $this->plugin->transform($roles, $this->migrateExecutable, $this->row, 'destinationproperty'); + $this->assertSame('user_role', $transformed_value['id']); + $this->assertSame('user.current_user', $transformed_value['context_mapping']['user']); + $this->assertSame('authenticated', $transformed_value['roles']['authenticated']); + } + +}