protected function MakeUniqueEntityField::exists in Drupal 10
Same name and namespace in other branches
- 8 core/modules/migrate/src/Plugin/migrate/process/MakeUniqueEntityField.php \Drupal\migrate\Plugin\migrate\process\MakeUniqueEntityField::exists()
- 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\processCode
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();
}
}