You are here

protected function AgreementSettings::getRoleId in Agreement 8.2

Same name and namespace in other branches
  1. 3.0.x src/Plugin/migrate/process/AgreementSettings.php \Drupal\agreement\Plugin\migrate\process\AgreementSettings::getRoleId()

Gets the new role ID from the old role name.

Parameters

string $value: The role name.

\Drupal\migrate\MigrateExecutableInterface $executable: The migration execution.

Return value

string The new role ID.

See also

\Drupal\migrate\Plugin\migrate\process\MachineName::transform()

\Drupal\user\Plugin\migrate\process\UserUpdate8002::transform()

1 call to AgreementSettings::getRoleId()
AgreementSettings::transform in src/Plugin/migrate/process/AgreementSettings.php
Performs the associated process.

File

src/Plugin/migrate/process/AgreementSettings.php, line 130

Class

AgreementSettings
Agreement settings process plugin.

Namespace

Drupal\agreement\Plugin\migrate\process

Code

protected function getRoleId($value, MigrateExecutableInterface $executable) {
  if ($value === 1) {
    return 'anonymous';
  }
  elseif ($value === 2) {
    return 'authenticated';
  }
  try {
    $row = new Row([
      'rid' => $value,
    ], [
      'rid' => [
        'type' => 'integer',
      ],
    ]);

    /** @var  \Drupal\migrate\Plugin\MigrationInterface $migration */
    $migration = $this->migrationPluginManager
      ->createInstance('d7_user_role');
    $configuration = [
      'source' => 'rid',
    ];
    $source_rid = $this->processPluginManager
      ->createInstance('get', $configuration, $this->migration)
      ->transform(NULL, $executable, $row, 'rid');
    if (!is_array($source_rid)) {
      $source_rid = [
        'rid' => $source_rid,
      ];
    }
    $source_id_values['d7_user_role'] = $source_rid;

    // Break out of the loop as soon as a destination ID is found.
    if ($destination_ids = $migration
      ->getIdMap()
      ->lookupDestinationIds($source_id_values['d7_user_role'])) {
      $collapsed_ids = reset($destination_ids);
      if (!empty($collapsed_ids)) {
        return reset($collapsed_ids);
      }
    }
    return $value;
  } catch (PluginException $e) {
    return $value;
  }
}