Namespace
Drupal\block\Plugin\migrate\process
File
core/modules/block/src/Plugin/migrate/process/RolesLookup.php
View source
<?php
namespace Drupal\block\Plugin\migrate\process;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\Attribute\MigrateProcess;
use Drupal\migrate\MigrateLookupInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
class RolesLookup extends ProcessPluginBase implements ContainerFactoryPluginInterface {
protected $migrateLookup;
protected $migration;
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrateLookupInterface $migrate_lookup) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->migrateLookup = $migrate_lookup;
if (isset($configuration['migration'])) {
$this->migration = $configuration['migration'];
}
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('migrate.lookup'));
}
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$roles = $row
->get('roles');
$roles_result = [];
if ($roles) {
foreach ($roles as $role_id) {
$lookup_result = $this->migrateLookup
->lookup([
$this->migration,
], [
$role_id,
]);
if ($lookup_result) {
$roles_result[$role_id] = $lookup_result[0]['id'];
}
}
}
return $roles_result;
}
}
Classes