I need a specific vocabulary (A) that has unique terms. I don't want to do validation at form level because I want to be able to add term from everywhere.
I successful used hook_entity_bundle_field_info_alter()
and addConstraint()
to be sure one specific field is unique on another vocabulary (B). (Will this be deprecated? See https://www.drupal.org/node/2346347.)
For the vocabulary (A), there is no specific field, so the hook_entity_bundle_field_info_alter()
is not working here, as this field name
is not a "true" field.
I use hook_entity_presave()
, but I'm not able to do a proper validation because this hook is called too late in the code, except if I use Exception, but that is not a good way.
How can I achieve what I am trying to do?