You are here

protected function MakeUniqueEntityField::exists in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/migrate/src/Plugin/migrate/process/MakeUniqueEntityField.php \Drupal\migrate\Plugin\migrate\process\MakeUniqueEntityField::exists()

This is a query checking the existence of some value.

Parameters

mixed $value: The value to check.

Return value

bool TRUE if the value exists.

Overrides MakeUniqueBase::exists

File

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

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