class PropertyNode in User Merge 2.x
Class PropertyNode.
@UserMergeProperty( id = "property_node", name = @Translation("Node data"), description = @Translation("Reassign nodes owned by the retired user."), review = "", ) @package Drupal\usermerge\Plugin\UserMerge\Property
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\usermerge\Plugin\UserMerge\Property\UserMergePropertyBase implements UserMergePropertyPluginInterface
- class \Drupal\usermerge\Plugin\UserMerge\Property\PropertyNode
- class \Drupal\usermerge\Plugin\UserMerge\Property\UserMergePropertyBase implements UserMergePropertyPluginInterface
Expanded class hierarchy of PropertyNode
File
- src/
Plugin/ UserMerge/ Property/ PropertyNode.php, line 25
Namespace
Drupal\usermerge\Plugin\UserMerge\PropertyView source
class PropertyNode extends UserMergePropertyBase {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* Constructs a \Drupal\Component\Plugin\PluginBase object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Database\Connection $connection
* The database connection.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, Connection $connection) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager);
$this->connection = $connection;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'), $container
->get('database'));
}
/**
* {@inheritDoc}
*/
public function process(UserInterface $retired, UserInterface $retained, array $settings = []) : void {
try {
$node_storage = $this->entityTypeManager
->getStorage('node');
} catch (PluginNotFoundException|InvalidPluginDefinitionException $e) {
throw new UserMergeException('Storage for node entity has not been found.');
}
// Anonymize nodes (current revisions).
$node_ids = $node_storage
->getQuery()
->condition('uid', $retired
->id())
->execute();
$nodes = $node_storage
->loadMultiple($node_ids);
try {
/** @var \Drupal\node\NodeInterface $node */
foreach ($nodes as $node) {
$node
->setOwnerId($retained
->id());
$node
->save();
}
} catch (EntityStorageException $e) {
throw new UserMergeException('An error occurred during nodes reassignment.');
}
// Anonymize old revisions.
$this->connection
->update('node_field_revision')
->fields([
'uid' => $retained
->id(),
])
->condition('uid', $retired
->id())
->execute();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
PropertyNode:: |
protected | property | The database connection. | |
PropertyNode:: |
public static | function |
Creates an instance of the plugin. Overrides UserMergePropertyBase:: |
|
PropertyNode:: |
public | function |
Process merge on selected property. Overrides UserMergePropertyPluginInterface:: |
|
PropertyNode:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides UserMergePropertyBase:: |
|
UserMergePropertyBase:: |
protected | property | Entity type manager. | |
UserMergePropertyBase:: |
public | function |
Return the name of the property plugin. Overrides UserMergePropertyPluginInterface:: |
|
UserMergePropertyBase:: |
public | function |
Get the review form if it is provided by the plugin. Overrides UserMergePropertyPluginInterface:: |