migration = $migration; $this->entityTypeManager = $entity_type_manager; } /** * {@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_type.manager') ); } /** * {@inheritdoc} */ protected function exists($value) { // Plugins are cached so for every run we need a new query object. $query = $this ->entityTypeManager ->getStorage($this->configuration['entity_type']) ->getQuery() ->condition($this->configuration['field'], $value); if (!empty($this->configuration['migrated'])) { // Check if each entity is in the ID map. $idMap = $this->migration->getIdMap(); foreach ($query->execute() as $id) { $dest_id_values[$this->configuration['field']] = $id; if ($idMap->lookupSourceID($dest_id_values)) { return TRUE; } } return FALSE; } else { // Just check if any such entity exists. return $query->count()->execute(); } } }