View source
<?php
namespace Drupal\shortcut\Plugin\migrate\destination;
use Drupal\shortcut\ShortcutSetStorageInterface;
use Drupal\user\Entity\User;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Row;
use Drupal\migrate\Plugin\migrate\destination\DestinationBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
class ShortcutSetUsers extends DestinationBase implements ContainerFactoryPluginInterface {
protected $shortcutSetStorage;
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, ShortcutSetStorageInterface $shortcut_set_storage) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
$this->shortcutSetStorage = $shortcut_set_storage;
}
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('entity_type.manager')
->getStorage('shortcut_set'));
}
public function getIds() {
return [
'set_name' => [
'type' => 'string',
],
'uid' => [
'type' => 'integer',
],
];
}
public function fields() {
return [
'uid' => 'The users.uid for this set.',
'source' => 'The shortcut_set.set_name that will be displayed for this user.',
];
}
public function import(Row $row, array $old_destination_id_values = []) {
$set = $this->shortcutSetStorage
->load($row
->getDestinationProperty('set_name'));
$account = User::load($row
->getDestinationProperty('uid'));
$this->shortcutSetStorage
->assignUser($set, $account);
return [
$set
->id(),
$account
->id(),
];
}
}