Skip to content
Snippets Groups Projects
Commit 82428b54 authored by Sven's avatar Sven
Browse files

Applies Changes from #45 and fixes a bug

parent f311267f
No related branches found
No related tags found
1 merge request!9210Close #2973863: Do not enforce data integrity on pre-existing entity references
......@@ -123,7 +123,21 @@ public function validate($value, Constraint $constraint): void {
if ($target_ids) {
if ($entity && !$entity->isNew()) {
$existing_entity = $this->entityTypeManager->getStorage($entity->getEntityTypeId())->loadUnchanged($entity->id());
$existing_target_ids = array_values(array_column($existing_entity->{$value->getFieldDefinition()->getName()}->getValue(), 'target_id'));
$existing_target_ids = [];
if ($existing_entity->isTranslatable()) {
foreach ($existing_entity->getTranslationLanguages() as $language) {
$existing_entity = $existing_entity->getTranslation($language->getId());
foreach ($existing_entity->{$value->getFieldDefinition()->getName()}->getValue() as $item) {
$existing_target_ids[$item['target_id']] = $item['target_id'];
}
}
}
else {
foreach ($existing_entity->{$value->getFieldDefinition()
->getName()}->getValue() as $item) {
$existing_target_ids[$item['target_id']] = $item['target_id'];
}
}
$target_ids = array_diff($target_ids, $existing_target_ids);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment