Problem/Motivation
Hi, I'm trying to replace the error message "This entity (user: 12) cannot be referenced." by a more appropriate message like : "The user test@test.com cannot be added. Maybe his account is blocked."
Steps to reproduce
On a content type, juste add a reference field which point to a view which give you a list of your active user.
Create a new node using your content type and ddd some of your active user. Save you new node.
Then go switch status to blocked for some of the user you added to your node.
Go back to edit your node but juste save it, don't make any change.
You will get a message saying "This entity (user: 12) cannot be referenced." (the 12 is an example of user ID).
If you have allow many user to be defined on your content type, the message will repeat as many time as you have user blocked.
Proposed resolution
- let the dev create there own constraint violation and hiding existing constraint violation
- create a page to let the user customize existing constraint violation
Just for people to know, I have already created my own constraint violation for this case but I can't hide the already existing constraint violation... So now I've got the 2 messages :
"This entity (user: 12) cannot be referenced.
The user test@test.com cannot be added. Maybe his account is blocked."
I've found on stackexchange that somebody told to edit the list of constraint violation with a hook_validation_constraint_alter(). But I didn't found how to use it properly....
I have also found the hook_entity_type_alter() example in the project
remove_entity_untranslatable_field_validation but when I tried, it disable the ValidReferenceConstraint on the page and not only on the field I have added... so I've got an error which say some field like date, address and other needed it.
So does somebody have a solution for this?
NB : sorry I'm not english, so I could have made some mistake on the support request.