diff --git a/validation/severity.rst b/validation/severity.rst index 7a8c22298fd..7df7746c7f2 100644 --- a/validation/severity.rst +++ b/validation/severity.rst @@ -50,6 +50,25 @@ Use the ``payload`` option to configure the error level for each constraint: protected $bankAccountNumber; } + .. code-block:: php-attributes + + // src/Entity/User.php + namespace App\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class User + { + #[Assert\NotBlank(payload: ['severity' => 'error'])] + protected $username; + + #[Assert\NotBlank(payload: ['severity' => 'error'])] + protected $password; + + #[Assert\Iban(payload: ['severity' => 'warning'])] + protected $bankAccountNumber; + } + .. code-block:: yaml # config/validator/validation.yaml diff --git a/validation/translations.rst b/validation/translations.rst index 5c22f9362c3..c251c986b3b 100644 --- a/validation/translations.rst +++ b/validation/translations.rst @@ -40,6 +40,19 @@ property is not empty, add the following: public $name; } + .. code-block:: php-attributes + + // src/Entity/Author.php + namespace App\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Author + { + #[Assert\NotBlank(message: 'author.name.not_blank')] + public $name; + } + .. code-block:: yaml # config/validator/validation.yaml