You are here

class UserMerger in User Merge 2.x

A service for merging two Drupal user accounts.

Hierarchy

Expanded class hierarchy of UserMerger

1 string reference to 'UserMerger'
usermerge.services.yml in ./usermerge.services.yml
usermerge.services.yml
1 service uses UserMerger
usermerge.user_merger in ./usermerge.services.yml
Drupal\usermerge\UserMerger

File

src/UserMerger.php, line 11

Namespace

Drupal\usermerge
View source
class UserMerger implements UserMergerInterface {

  /**
   * Property plugin manager.
   *
   * @var \Drupal\Component\Plugin\PluginManagerInterface
   */
  protected $propertyPluginManager;

  /**
   * Action plugin manager.
   *
   * @var \Drupal\Component\Plugin\PluginManagerInterface
   */
  protected $actionPluginManager;

  /**
   * Creates a user merger object.
   *
   * @param \Drupal\Component\Plugin\PluginManagerInterface $property_manager
   *   Property plugin manager.
   * @param \Drupal\Component\Plugin\PluginManagerInterface $action_manager
   *   Action plugin manager.
   */
  public function __construct(PluginManagerInterface $property_manager, PluginManagerInterface $action_manager) {
    $this->propertyPluginManager = $property_manager;
    $this->actionPluginManager = $action_manager;
  }

  /**
   * {@inheritdoc}
   */
  public function merge(UserInterface $retire_user, UserInterface $retain_user, $action_id = 'action_block') {
    $this
      ->applyAction($action_id, $retire_user, $retain_user);
    foreach ($this
      ->getPropertyPlugins() as $plugin_id) {
      $this
        ->applyProperty($plugin_id, $retire_user, $retain_user);
    }
    return $retain_user;
  }

  /**
   * {@inheritdoc}
   */
  public function applyAction($plugin_id, UserInterface $retire_user, UserInterface $retain_user) {
    $this->actionPluginManager
      ->createInstance($plugin_id)
      ->process($retire_user, $retain_user);
  }

  /**
   * {@inheritdoc}
   */
  public function applyProperty($plugin_id, UserInterface $retire_user, UserInterface $retain_user, array $settings = []) {
    $this->propertyPluginManager
      ->createInstance($plugin_id)
      ->process($retire_user, $retain_user, $settings);
  }

  /**
   * {@inheritdoc}
   */
  public function getPropertyPlugins() {
    $plugin_ids = [];
    foreach ($this->propertyPluginManager
      ->getDefinitions() as $plugin_id => $definition) {
      $plugin_ids[] = $plugin_id;
    }
    return $plugin_ids;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
UserMerger::$actionPluginManager protected property Action plugin manager.
UserMerger::$propertyPluginManager protected property Property plugin manager.
UserMerger::applyAction public function Applies the action to take on the user account being retired. Overrides UserMergerInterface::applyAction
UserMerger::applyProperty public function Applies a property plugin to a set of accounts being merged. Overrides UserMergerInterface::applyProperty
UserMerger::getPropertyPlugins public function Gets a list of property plugin ids. Overrides UserMergerInterface::getPropertyPlugins
UserMerger::merge public function Merges two user accounts. Overrides UserMergerInterface::merge
UserMerger::__construct public function Creates a user merger object.