"Fossies" - the Fresh Open Source Software Archive

Member "drupal-8.9.9/core/modules/user/src/Plugin/migrate/destination/UserData.php" (18 Nov 2020, 2567 Bytes) of package /linux/www/drupal-8.9.9.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "UserData.php" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 9.0.8_vs_9.1.0-rc1.

    1 <?php
    2 
    3 namespace Drupal\user\Plugin\migrate\destination;
    4 
    5 use Drupal\migrate\Plugin\MigrationInterface;
    6 use Drupal\user\UserData as UserDataStorage;
    7 use Drupal\migrate\Row;
    8 use Drupal\migrate\Plugin\migrate\destination\DestinationBase;
    9 use Symfony\Component\DependencyInjection\ContainerInterface;
   10 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
   11 
   12 /**
   13  * @MigrateDestination(
   14  *   id = "user_data"
   15  * )
   16  */
   17 class UserData extends DestinationBase implements ContainerFactoryPluginInterface {
   18 
   19   /**
   20    * @var \Drupal\user\UserData
   21    */
   22   protected $userData;
   23 
   24   /**
   25    * Builds an user data entity destination.
   26    *
   27    * @param array $configuration
   28    *   A configuration array containing information about the plugin instance.
   29    * @param string $plugin_id
   30    *   The plugin_id for the plugin instance.
   31    * @param mixed $plugin_definition
   32    *   The plugin implementation definition.
   33    * @param \Drupal\migrate\Plugin\MigrationInterface $migration
   34    *   The migration.
   35    * @param \Drupal\user\UserData $user_data
   36    *   The user data service.
   37    */
   38   public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, UserDataStorage $user_data) {
   39     parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
   40     $this->userData = $user_data;
   41   }
   42 
   43   /**
   44    * {@inheritdoc}
   45    */
   46   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
   47     return new static(
   48       $configuration,
   49       $plugin_id,
   50       $plugin_definition,
   51       $migration,
   52       $container->get('user.data')
   53     );
   54   }
   55 
   56   /**
   57    * {@inheritdoc}
   58    */
   59   public function import(Row $row, array $old_destination_id_values = []) {
   60     $uid = $row->getDestinationProperty('uid');
   61     $module = $row->getDestinationProperty('module');
   62     $key = $row->getDestinationProperty('key');
   63     $this->userData->set($module, $uid, $key, $row->getDestinationProperty('settings'));
   64 
   65     return [$uid, $module, $key];
   66   }
   67 
   68   /**
   69    * {@inheritdoc}
   70    */
   71   public function getIds() {
   72     $ids['uid']['type'] = 'integer';
   73     $ids['module']['type'] = 'string';
   74     $ids['key']['type'] = 'string';
   75     return $ids;
   76   }
   77 
   78   /**
   79    * {@inheritdoc}
   80    */
   81   public function fields(MigrationInterface $migration = NULL) {
   82     return [
   83       'uid' => 'The user id.',
   84       'module' => 'The module name responsible for the settings.',
   85       'key' => 'The setting key to save under.',
   86       'settings' => 'The settings to save.',
   87     ];
   88   }
   89 
   90 }