diff --git a/core/modules/block/src/Plugin/migrate/process/d6/BlockVisibility.php b/core/modules/block/src/Plugin/migrate/process/d6/BlockVisibility.php index cae1aca..00dd1cc 100644 --- a/core/modules/block/src/Plugin/migrate/process/d6/BlockVisibility.php +++ b/core/modules/block/src/Plugin/migrate/process/d6/BlockVisibility.php @@ -7,8 +7,10 @@ namespace Drupal\block\Plugin\migrate\process\d6; +use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\migrate\MigrateExecutableInterface; +use Drupal\migrate\MigrateSkipRowException; use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\Row; use Drupal\migrate\Entity\MigrationInterface; @@ -30,12 +32,20 @@ class BlockVisibility extends ProcessPluginBase implements ContainerFactoryPlugi protected $migrationPlugin; /** + * The module handler. + * + * @var \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected $moduleHandler; + + /** * {@inheritdoc} */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, MigrateProcessInterface $migration_plugin) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, MigrateProcessInterface $migration_plugin, ModuleHandlerInterface $module_handler) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->migration = $migration; $this->migrationPlugin = $migration_plugin; + $this->moduleHandler = $module_handler; } /** @@ -47,7 +57,8 @@ public static function create(ContainerInterface $container, array $configuratio $plugin_id, $plugin_definition, $migration, - $container->get('plugin.manager.migrate.process')->createInstance('migration', array('migration' => 'd6_user_role'), $migration) + $container->get('plugin.manager.migrate.process')->createInstance('migration', array('migration' => 'd6_user_role'), $migration), + $container->get('module_handler') ); } /** @@ -60,13 +71,27 @@ public function transform($value, MigrateExecutableInterface $migrate_executable $visibility = array(); if (!empty($pages)) { - $paths = preg_split("(\r\n?|\n)", $pages); - foreach ($paths as $key => $path) { - $paths[$key] = $path === '' ? $path : "/$path"; - } - $visibility['request_path']['pages'] = implode ("\n", $paths); $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 MigrateSkipRowException(); + } + } + // 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)) {