You are here

class PropertyFlag in User Merge 2.x

Class PropertyFlag.

@UserMergeProperty( id = "property_flag", name = @Translation("Flag data"), description = @Translation("Reassign flaging entities associated with the retired user."), review = "", provider = "flag" )

@package Drupal\usermerge\Plugin\UserMerge\Property

Hierarchy

Expanded class hierarchy of PropertyFlag

File

src/Plugin/UserMerge/Property/PropertyFlag.php, line 27

Namespace

Drupal\usermerge\Plugin\UserMerge\Property
View source
class PropertyFlag extends UserMergePropertyBase {

  /**
   * Flag service.
   *
   * @var \Drupal\flag\FlagServiceInterface
   */
  protected $flag;

  /**
   * PropertyComment constructor.
   *
   * @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\flag\FlagServiceInterface $flag
   *   Flag service.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, FlagServiceInterface $flag) {
    parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager);
    $this->flag = $flag;
  }

  /**
   * {@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('flag'));
  }

  /**
   * {@inheritDoc}
   */
  public function process(UserInterface $retired, UserInterface $retained, array $settings = []) : void {
    try {
      $flagging_storage = $this->entityTypeManager
        ->getStorage('flagging');
    } catch (PluginNotFoundException|InvalidPluginDefinitionException $e) {
      throw new UserMergeException('Storage for flagging entity has not been found.');
    }
    $flaggings_ids = $flagging_storage
      ->getQuery()
      ->condition('uid', $retired
      ->id())
      ->sort('flag_id')
      ->execute();

    /** @var \Drupal\flag\FlaggingInterface[] $flaggings */
    $flaggings = $flagging_storage
      ->loadMultiple($flaggings_ids);
    try {
      foreach ($flaggings as $flagging) {
        $flag = $flagging
          ->getFlag();
        $entity = $flagging
          ->getFlaggable();
        if (!$flag
          ->isFlagged($entity, $retained)) {
          $flagging
            ->setOwner($retained);
          $flagging
            ->save();
        }
      }
    } catch (EntityStorageException $e) {
      throw new UserMergeException('An error occurred during flag reassignment.');
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 2
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PropertyFlag::$flag protected property Flag service.
PropertyFlag::create public static function Creates an instance of the plugin. Overrides UserMergePropertyBase::create
PropertyFlag::process public function Process merge on selected property. Overrides UserMergePropertyPluginInterface::process
PropertyFlag::__construct public function PropertyComment constructor. Overrides UserMergePropertyBase::__construct
UserMergePropertyBase::$entityTypeManager protected property Entity type manager.
UserMergePropertyBase::getName public function Return the name of the property plugin. Overrides UserMergePropertyPluginInterface::getName
UserMergePropertyBase::getReviewForm public function Get the review form if it is provided by the plugin. Overrides UserMergePropertyPluginInterface::getReviewForm