3 namespace Drupal\shortcut\Plugin\migrate\destination;
5 use Drupal\shortcut\ShortcutSetStorageInterface;
6 use Drupal\user\Entity\User;
7 use Drupal\migrate\Plugin\MigrationInterface;
8 use Drupal\migrate\Row;
9 use Drupal\migrate\Plugin\migrate\destination\DestinationBase;
10 use Symfony\Component\DependencyInjection\ContainerInterface;
11 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
14 * @MigrateDestination(
15 * id = "shortcut_set_users"
18 class ShortcutSetUsers extends DestinationBase implements ContainerFactoryPluginInterface {
21 * The shortcut set storage handler.
23 * @var \Drupal\shortcut\ShortcutSetStorageInterface
25 protected $shortcutSetStorage;
28 * Constructs an entity destination plugin.
30 * @param array $configuration
31 * A configuration array containing information about the plugin instance.
32 * @param string $plugin_id
33 * The plugin_id for the plugin instance.
34 * @param mixed $plugin_definition
35 * The plugin implementation definition.
36 * @param \Drupal\migrate\Plugin\MigrationInterface $migration
38 * @param \Drupal\shortcut\ShortcutSetStorageInterface $shortcut_set_storage
39 * The shortcut_set entity storage handler.
41 public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, ShortcutSetStorageInterface $shortcut_set_storage) {
42 parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
43 $this->shortcutSetStorage = $shortcut_set_storage;
49 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
55 $container->get('entity.manager')->getStorage('shortcut_set')
62 public function getIds() {
76 public function fields(MigrationInterface $migration = NULL) {
78 'uid' => 'The users.uid for this set.',
79 'source' => 'The shortcut_set.set_name that will be displayed for this user.',
86 public function import(Row $row, array $old_destination_id_values = []) {
87 /** @var \Drupal\shortcut\ShortcutSetInterface $set */
88 $set = $this->shortcutSetStorage->load($row->getDestinationProperty('set_name'));
89 /** @var \Drupal\user\UserInterface $account */
90 $account = User::load($row->getDestinationProperty('uid'));
91 $this->shortcutSetStorage->assignUser($set, $account);
93 return [$set->id(), $account->id()];