summaryrefslogtreecommitdiffstatshomepage
path: root/core/modules/user/src/Plugin/migrate/ProfileValues.php
blob: 573c9b557a83de03293222f1f0c1a1e455e842b3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php

namespace Drupal\user\Plugin\migrate;

use Drupal\migrate\Exception\RequirementsException;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\Plugin\Migration;

/**
 * Plugin class for user migrations dealing with profile values.
 */
class ProfileValues extends Migration {

  /**
   * Flag determining whether the process plugin has been initialized.
   *
   * @var bool
   */
  protected $init = FALSE;

  /**
   * {@inheritdoc}
   */
  public function getProcess() {
    if (!$this->init) {
      $this->init = TRUE;
      $definition['source'] = [
        'plugin' => 'profile_field',
        'ignore_map' => TRUE,
      ] + $this->source;
      $definition['destination']['plugin'] = 'null';
      $definition['idMap']['plugin'] = 'null';
      try {
        $this->checkRequirements();
        $profile_field_migration = $this->migrationPluginManager->createStubMigration($definition);
        $migrate_executable = new MigrateExecutable($profile_field_migration);
        $source_plugin = $profile_field_migration->getSourcePlugin();
        $source_plugin->checkRequirements();
        foreach ($source_plugin as $row) {
          $name = $row->getSourceProperty('name');
          $fid = $row->getSourceProperty('fid');
          // The user profile field name can be greater than 32 characters. Use
          // the migrated profile field name in the process pipeline.
          $configuration =
            [
              'migration' => 'user_profile_field',
              'source_ids' => $fid,
              'no_stub' => TRUE,
            ];
          $plugin = $this->processPluginManager->createInstance('migration_lookup', $configuration, $profile_field_migration);
          $new_value = $plugin->transform($fid, $migrate_executable, $row, 'tmp');
          if (isset($new_value[1])) {
            // Set the destination to the migrated profile field name.
            $this->process[$new_value[1]] = $name;
          }
        }
      }
      catch (RequirementsException) {
        // The checkRequirements() call will fail when the profile module does
        // not exist on the source site, or if the required migrations have not
        // yet run.
      }
    }
    return parent::getProcess();
  }

}