I am trying to prevent removal of an entity when it has some specific content. So I added a validation rules, and it is working perfectly with a regular controler using a form validation.
//entity
/**
* @Assert\IsTrue(message="Delete not allowed", groups="delete")
*
* @return bool
*/
public function isDeleteAllowed(): bool
{
//some logic here...
return false;
}
Now I want to reuse the same logic for the api-platform part. I have setup a validation group for the delete action of my entity
//entity
/**
* @ApiResource(
* itemOperations={
* "delete"={
* "validation_groups"={"delete"}
* }
* })
*/
However the api-platform DELETE action is skipping validation. How can I enforce it?
For your information, I found the reason why it is not working in the api-platform source code where they deliberately ignore validation on DELETE action. So I opened a ticket to see if it can be fixed Validation on DELETE action