You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: core/validation.md
+83Lines changed: 83 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -377,6 +377,89 @@ class Greeting
377
377
}
378
378
```
379
379
380
+
## Validating Delete Operations
381
+
382
+
By default, validation rules that are specified on the API resource are not evaluated during DELETE operations. You need to trigger the validation in your code, if needed.
383
+
384
+
Assume that you have the following entity that uses a custom delete validator:
385
+
386
+
```php
387
+
<?php
388
+
// api/src/Entity/MyEntity.php
389
+
390
+
namespace App\Entity;
391
+
392
+
use ApiPlatform\Core\Annotation\ApiResource;
393
+
use App\Validator\AssertCanDelete;
394
+
use Doctrine\ORM\Mapping as ORM;
395
+
396
+
#[ORM\Entity]
397
+
#[ApiResource(
398
+
itemOperations: [
399
+
'delete' => [
400
+
'validation_groups' => ['deleteValidation']
401
+
]
402
+
]
403
+
)]
404
+
#[AssertCanDelete(groups: ['deleteValidation'])]
405
+
class MyEntity
406
+
{
407
+
#[ORM\Id, ORM\Column, ORM\GeneratedValue]
408
+
private ?int $id = null;
409
+
410
+
#[ORM\Column]
411
+
public string $name = '';
412
+
}
413
+
```
414
+
415
+
Create a data persister, which decorates the default data persister, where you will trigger the validation:
As stated in the [Symfony documentation](https://symfony.com/doc/current/validation/severity.html), you can use the payload field to define error levels.
0 commit comments