I'm building a module that get information from the NCBI database API -- specifically it get's publications, from my group, by using a publication ID. I want anyone in the group to be able to add a publication to our site, however, to do this I need to make sure that the ID's being input are only input one time since they are all unique.
I've already set up a system that checks whether someone else has already submitted that value. I did this by building a constraint and constraint validator on that specific field that uses this query
$query = \Drupal::entityQuery($entity_type_id) ->condition($field_name, $id, '=') ->execute();
My current issue that I haven't been able to circumvent is in the event the user needs to update/change information in the fields on a node that has already been submitted, the validator is still run on that ID field and throws an error that this ID already exists - hence changes are not saved. I figure the easiest solution is to figure out if there's a way to remove the constraint property on the field only if the field is the same as it was previously. That way, if a user needs to edit that particular node, when they save the changes, the validator for the ID field doesn't throw an error.