🐛 | Corresponding Entity References | Corresponding entity reference using same field and same bundle results in unexpected behavior
🇸🇮Slovenia jurecop
I solved this using the hook_cer_differences_alter, by filtering entities by field bundle:
hook_cer_differences_alter(\Drupal\Core\Entity\ContentEntityInterface $entity,
array &$differences, $correspondingField
): void {
$allowedFieldBundles = [
'field_bundle_type' => 'bundle_type',
];
if (!empty($differences['add'])) {
$hasKey = array_key_exists($correspondingField, $allowedFieldBundles);
if ($entity instanceof \Drupal\node\NodeInterface && $hasKey) {
$entityType = $entity->bundle();
if ($allowedFieldBundles[$correspondingField] !== $entityType) {
$differences = ['add' => [], 'remove' => []];
}
}
}
}