PiwikVisibilityPages.php in Piwik Web Analytics 8
File
src/Plugin/migrate/process/PiwikVisibilityPages.php
View source
<?php
namespace Drupal\piwik\Plugin\migrate\process;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\MigrateSkipRowException;
use Drupal\migrate\Plugin\MigrateProcessInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
class PiwikVisibilityPages extends ProcessPluginBase implements ContainerFactoryPluginInterface {
protected $moduleHandler;
protected $migrationPlugin;
protected $skipPHP = FALSE;
public function __construct(array $configuration, $plugin_id, $plugin_definition, ModuleHandlerInterface $module_handler, MigrateProcessInterface $migration_plugin) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->moduleHandler = $module_handler;
$this->migrationPlugin = $migration_plugin;
if (isset($configuration['skip_php'])) {
$this->skipPHP = $configuration['skip_php'];
}
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
$migration_configuration = [
'migration' => [
'd6_user_role',
'd7_user_role',
],
];
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('module_handler'), $container
->get('plugin.manager.migrate.process')
->createInstance('migration', $migration_configuration, $migration));
}
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
list($old_visibility, $pages) = $value;
$request_path_pages = '';
if ($pages) {
if ($old_visibility == 2) {
if ($this->moduleHandler
->moduleExists('php')) {
$request_path_pages = $pages;
}
elseif ($this->skipPHP) {
throw new MigrateSkipRowException();
}
}
else {
$paths = preg_split("(\r\n?|\n)", $pages);
foreach ($paths as $key => $path) {
$paths[$key] = $path === '<front>' ? $path : '/' . ltrim($path, '/');
}
$request_path_pages = implode("\n", $paths);
}
}
return $request_path_pages;
}
}