Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. MakeUniqueEntityField.php

function MakeUniqueEntityField::exists

Overrides MakeUniqueBase::exists

File

core/modules/migrate/src/Plugin/migrate/process/MakeUniqueEntityField.php, line 123

Class

MakeUniqueEntityField
Ensures the source value is made unique against an entity field.

Namespace

Drupal\migrate\Plugin\migrate\process

Code

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()
        ->accessCheck(FALSE)
        ->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();
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal