protected function EntityLookup::query in Migrate Plus 8.3
Same name and namespace in other branches
- 8.5 src/Plugin/migrate/process/EntityLookup.php \Drupal\migrate_plus\Plugin\migrate\process\EntityLookup::query()
- 8.2 src/Plugin/migrate/process/EntityLookup.php \Drupal\migrate_plus\Plugin\migrate\process\EntityLookup::query()
- 8.4 src/Plugin/migrate/process/EntityLookup.php \Drupal\migrate_plus\Plugin\migrate\process\EntityLookup::query()
Checks for the existence of some value.
Parameters
$value: The value to query.
Return value
mixed|null Entity id if the queried entity exists. Otherwise NULL.
1 call to EntityLookup::query()
- EntityLookup::transform in src/
Plugin/ migrate/ process/ EntityLookup.php - Performs the associated process.
File
- src/
Plugin/ migrate/ process/ EntityLookup.php, line 207
Class
- EntityLookup
- This plugin looks for existing entities.
Namespace
Drupal\migrate_plus\Plugin\migrate\processCode
protected function query($value) {
// Entity queries typically are case-insensitive. Therefore, we need to
// handle case sensitive filtering as a post-query step. By default, it
// filters case insensitive. Change to true if that is not the desired
// outcome.
$ignoreCase = !empty($this->configuration['ignore_case']) ?: FALSE;
$multiple = is_array($value);
$query = $this->entityManager
->getStorage($this->lookupEntityType)
->getQuery()
->condition($this->lookupValueKey, $value, $multiple ? 'IN' : NULL);
if ($this->lookupBundleKey) {
$query
->condition($this->lookupBundleKey, $this->lookupBundle);
}
$results = $query
->execute();
if (empty($results)) {
return NULL;
}
// By default do a case-sensitive comparison.
if (!$ignoreCase) {
// Returns the entity's identifier.
foreach ($results as $k => $identifier) {
$result_value = $this->entityManager
->getStorage($this->lookupEntityType)
->load($identifier)->{$this->lookupValueKey}->value;
if ($multiple && !in_array($result_value, $value, TRUE) || !$multiple && $result_value !== $value) {
unset($results[$k]);
}
}
}
if ($multiple && !empty($this->destinationProperty)) {
array_walk($results, function (&$value) {
$value = [
$this->destinationProperty => $value,
];
});
}
return $multiple ? array_values($results) : reset($results);
}