PiwikVisibilityRoles.php in Piwik Web Analytics 8        
                          
                  
                        
  
  
  
  
  
File
  src/Plugin/migrate/process/PiwikVisibilityRoles.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\Plugin\MigrateProcessInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
class PiwikVisibilityRoles extends ProcessPluginBase implements ContainerFactoryPluginInterface {
  
  protected $moduleHandler;
  
  protected $migrationPlugin;
  
  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;
  }
  
  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($roles) = $value;
    
    $roles = array_filter($roles);
    $user_role_roles = [];
    if ($roles) {
      foreach ($roles as $key => $role_id) {
        $roles[$key] = $this->migrationPlugin
          ->transform($role_id, $migrate_executable, $row, $destination_property);
      }
      $user_role_roles = array_combine($roles, $roles);
    }
    return $user_role_roles;
  }
}