You are here

DedupeEntity.php in Zircon Profile 8

Same filename and directory in other branches
  1. 8.0 core/modules/migrate/src/Plugin/migrate/process/DedupeEntity.php

File

core/modules/migrate/src/Plugin/migrate/process/DedupeEntity.php
View source
<?php

/**
 * @file
 * Contains \Drupal\migrate\Plugin\migrate\process\DedupeEntity.
 */
namespace Drupal\migrate\Plugin\migrate\process;

use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\Entity\MigrationInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Ensures value is not duplicated against an entity field.
 *
 * @MigrateProcessPlugin(
 *   id = "dedupe_entity"
 * )
 */
class DedupeEntity extends DedupeBase implements ContainerFactoryPluginInterface {

  /**
   * @var \Drupal\Core\Entity\Query\QueryFactoryInterface
   */
  protected $entityQueryFactory;

  /**
   * {@inheritdoc}
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, QueryFactory $entity_query_factory) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->entityQueryFactory = $entity_query_factory;
  }

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

  /**
   * {@inheritdoc}
   */
  protected function exists($value) {

    // Plugins are cached so for every run we need a new query object.
    return $this->entityQueryFactory
      ->get($this->configuration['entity_type'], 'AND')
      ->condition($this->configuration['field'], $value)
      ->count()
      ->execute();
  }

}

Classes

Namesort descending Description
DedupeEntity Ensures value is not duplicated against an entity field.