class AgreementSettings in Agreement 3.0.x
Same name and namespace in other branches
- 8.2 src/Plugin/migrate/process/AgreementSettings.php \Drupal\agreement\Plugin\migrate\process\AgreementSettings
Agreement settings process plugin.
Plugin annotation
@MigrateProcessPlugin(
id = "agreement_settings"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\migrate\ProcessPluginBase implements MigrateProcessInterface
- class \Drupal\agreement\Plugin\migrate\process\AgreementSettings implements ContainerFactoryPluginInterface
- class \Drupal\migrate\ProcessPluginBase implements MigrateProcessInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of AgreementSettings
File
- src/
Plugin/ migrate/ process/ AgreementSettings.php, line 22
Namespace
Drupal\agreement\Plugin\migrate\processView source
class AgreementSettings extends ProcessPluginBase implements ContainerFactoryPluginInterface {
/**
* Migration.
*
* @var \Drupal\migrate\Plugin\MigrationInterface
*/
protected $migration;
/**
* The process plugin manager.
*
* @var \Drupal\migrate\Plugin\MigratePluginManagerInterface
*/
protected $processPluginManager;
/**
* The migration plugin manager.
*
* @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface
*/
protected $migrationPluginManager;
/**
* Initialize method.
*
* @param array $configuration
* The plugin configuration.
* @param string $plugin_id
* The plugin ID.
* @param array $plugin_definition
* The plugin definition.
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
* This migration.
* @param \Drupal\migrate\Plugin\MigrationPluginManagerInterface $migration_plugin_manager
* Migration plugin manager.
* @param \Drupal\migrate\Plugin\MigratePluginManagerInterface $process_plugin_manager
* Process plugin manager.
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, MigrationInterface $migration, MigrationPluginManagerInterface $migration_plugin_manager, MigratePluginManagerInterface $process_plugin_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->migration = $migration;
$this->migrationPluginManager = $migration_plugin_manager;
$this->processPluginManager = $process_plugin_manager;
}
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
// Change property name for email recipient.
$value['recipient'] = $value['email_recipient'];
unset($value['email_recipient']);
// Deal with roles which may not have been upgraded.
if (!is_array($value['role'])) {
$value['roles'] = [
$this
->getRoleId($value['role'], $migrate_executable),
];
}
else {
$value['roles'] = [];
foreach ($value['role'] as $role) {
$value['roles'][] = $this
->getRoleId($role, $migrate_executable);
}
}
unset($value['role']);
// Map visibility settings and pages.
$value['visibility'] = [
'settings' => (int) $value['visibility_settings'],
'pages' => [],
];
$pages = preg_split('/\\r?\\n/', $value['visibility_pages']);
if (!empty($pages)) {
foreach ($pages as $page) {
if ($page) {
$value['visibility']['pages'][] = '/' . $page;
}
}
}
unset($value['visibility_pages']);
unset($value['visibility_settings']);
// Set a reset date.
$value['reset_date'] = 0;
// Prefix destination path.
$value['destination'] = !empty($value['destination']) ? '/' . $value['destination'] : '';
return $value;
}
/**
* Gets the new role ID from the old role name.
*
* @param string $value
* The role name.
* @param \Drupal\migrate\MigrateExecutableInterface $executable
* The migration execution.
*
* @return string
* The new role ID.
*
* @see \Drupal\migrate\Plugin\migrate\process\MachineName::transform()
* @see \Drupal\user\Plugin\migrate\process\UserUpdate8002::transform()
*/
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;
}
}
/**
* {@inheritdoc}
*/
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('plugin.manager.migration'), $container
->get('plugin.manager.migrate.process'));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AgreementSettings:: |
protected | property | Migration. | |
AgreementSettings:: |
protected | property | The migration plugin manager. | |
AgreementSettings:: |
protected | property | The process plugin manager. | |
AgreementSettings:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
AgreementSettings:: |
protected | function | Gets the new role ID from the old role name. | |
AgreementSettings:: |
public | function |
Performs the associated process. Overrides ProcessPluginBase:: |
|
AgreementSettings:: |
public | function |
Initialize method. Overrides PluginBase:: |
|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
ProcessPluginBase:: |
public | function |
Indicates whether the returned value requires multiple handling. Overrides MigrateProcessInterface:: |
3 |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |