the easiest way is to add a listener in the buildForm of the AbstractType class, here an example
$builder->addEventListener(
FormEvents::POST_SUBMIT,
function (FormEvent $event) {
$form = $event->getForm();
$coll1 = $form['field1']->getData();
$coll2 = $form['field2']->getData();
$ids1 = $coll1->map(function($entity) { return $entity->getId(); })->toArray();
$ids2 = $coll1->map(function($entity) { return $entity->getId(); })->toArray();
$intersect = array_intersect($ids1, $ids2);
if (!empty($intersect)) {
$form['field1']->addError(
new FormError('here the error')
);
}
}
);
Note that I have not tested the intersection of the collections but I hope the meaning is clear
Another (a bit hardest) way is to create a custom validation constraint