diff --git a/src/bundle/Controller/UserRegisterController.php b/src/bundle/Controller/UserRegisterController.php index 5ce6f7b..af05ba1 100644 --- a/src/bundle/Controller/UserRegisterController.php +++ b/src/bundle/Controller/UserRegisterController.php @@ -69,7 +69,7 @@ public function registerConfirmAction(): ConfirmView public function registerFromInvitationAction(Request $request): Response|FormView { - $invitation = $this->invitationService->getInvitation($request->get('inviteHash')); + $invitation = $this->invitationService->getInvitation($request->attributes->get('inviteHash')); if (!$this->invitationService->isValid($invitation)) { throw new UnauthorizedHttpException('You are not allowed to register a new account'); diff --git a/src/lib/Form/Type/UserPasswordChangeType.php b/src/lib/Form/Type/UserPasswordChangeType.php index 383b702..5bfd66f 100644 --- a/src/lib/Form/Type/UserPasswordChangeType.php +++ b/src/lib/Form/Type/UserPasswordChangeType.php @@ -35,10 +35,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'first_options' => ['label' => /** @Desc("New password") */ 'ezplatform.change_user_password.new_password'], 'second_options' => ['label' => /** @Desc("Confirm password") */ 'ezplatform.change_user_password.confirm_new_password'], 'constraints' => [ - new Password([ - 'contentType' => $options['content_type'], - 'user' => $options['user'] ?? null, - ]), + new Password( + contentType: $options['content_type'], + user: $options['user'] ?? null, + ), ], ]) ->add( diff --git a/src/lib/Form/Type/UserPasswordResetType.php b/src/lib/Form/Type/UserPasswordResetType.php index 6b6ad4c..69e7073 100644 --- a/src/lib/Form/Type/UserPasswordResetType.php +++ b/src/lib/Form/Type/UserPasswordResetType.php @@ -32,10 +32,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'second_options' => ['label' => /** @Desc("Confirm password") */ 'ezplatform.reset_user_password.confirm_new_password'], 'constraints' => [ new Password( - [ - 'contentType' => $options['content_type'], - 'user' => $options['user'] ?? null, - ] + contentType: $options['content_type'], + user: $options['user'] ?? null, ), ], ]) diff --git a/src/lib/Validator/Constraints/EmailInvitation.php b/src/lib/Validator/Constraints/EmailInvitation.php index fe6dcbc..81d6bc7 100644 --- a/src/lib/Validator/Constraints/EmailInvitation.php +++ b/src/lib/Validator/Constraints/EmailInvitation.php @@ -10,6 +10,7 @@ use JMS\TranslationBundle\Model\Message; use JMS\TranslationBundle\Translation\TranslationContainerInterface; +use Symfony\Component\Validator\Attribute\HasNamedArguments; use Symfony\Component\Validator\Constraint; /** @@ -19,6 +20,20 @@ class EmailInvitation extends Constraint implements TranslationContainerInterfac { public string $message = 'ibexa.user.invitation.user_with_email_exists'; + /** + * @param array|null $groups + */ + #[HasNamedArguments] + public function __construct( + ?string $message = null, + ?array $groups = null, + mixed $payload = null, + ) { + parent::__construct(null, $groups, $payload); + + $this->message = $message ?? $this->message; + } + public static function getTranslationMessages(): array { return [ diff --git a/src/lib/Validator/Constraints/Password.php b/src/lib/Validator/Constraints/Password.php index c20956f..0f9a6cd 100644 --- a/src/lib/Validator/Constraints/Password.php +++ b/src/lib/Validator/Constraints/Password.php @@ -10,6 +10,7 @@ use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType; use Ibexa\Contracts\Core\Repository\Values\User\User; +use Symfony\Component\Validator\Attribute\HasNamedArguments; use Symfony\Component\Validator\Constraint; /** @@ -23,6 +24,24 @@ class Password extends Constraint public ?User $user = null; + /** + * @param array|null $groups + */ + #[HasNamedArguments] + public function __construct( + ?ContentType $contentType = null, + ?User $user = null, + ?string $message = null, + ?array $groups = null, + mixed $payload = null, + ) { + parent::__construct(null, $groups, $payload); + + $this->contentType = $contentType; + $this->user = $user; + $this->message = $message ?? $this->message; + } + #[\Override] public function getTargets(): array { diff --git a/src/lib/Validator/Constraints/UserPassword.php b/src/lib/Validator/Constraints/UserPassword.php index f0d7823..1ba6fdd 100644 --- a/src/lib/Validator/Constraints/UserPassword.php +++ b/src/lib/Validator/Constraints/UserPassword.php @@ -10,6 +10,7 @@ use JMS\TranslationBundle\Model\Message; use JMS\TranslationBundle\Translation\TranslationContainerInterface; +use Symfony\Component\Validator\Attribute\HasNamedArguments; use Symfony\Component\Validator\Constraint; /** @@ -19,6 +20,20 @@ class UserPassword extends Constraint implements TranslationContainerInterface { public string $message = 'ezplatform.change_user_password.not_match'; + /** + * @param array|null $groups + */ + #[HasNamedArguments] + public function __construct( + ?string $message = null, + ?array $groups = null, + mixed $payload = null, + ) { + parent::__construct(null, $groups, $payload); + + $this->message = $message ?? $this->message; + } + /** * @return \JMS\TranslationBundle\Model\Message[] */ diff --git a/tests/lib/Validator/Constraint/PasswordValidatorTest.php b/tests/lib/Validator/Constraint/PasswordValidatorTest.php index b3f1882..cce89c3 100644 --- a/tests/lib/Validator/Constraint/PasswordValidatorTest.php +++ b/tests/lib/Validator/Constraint/PasswordValidatorTest.php @@ -85,10 +85,10 @@ static function (string $actualPassword, PasswordValidationContext $actualContex $this->validator->validate( $password, - new Password([ - 'contentType' => $contentType, - 'user' => $user, - ]) + new Password( + contentType: $contentType, + user: $user, + ) ); } @@ -140,9 +140,9 @@ public function testInvalid(): void ->expects(self::once()) ->method('addViolation'); - $this->validator->validate('pass', new Password([ - 'contentType' => $contentType, - ])); + $this->validator->validate('pass', new Password( + contentType: $contentType, + )); } public function testPluralValidationErrorUsesPluralMessageTemplate(): void @@ -174,9 +174,9 @@ public function testPluralValidationErrorUsesPluralMessageTemplate(): void ->with('plural error') ->willReturn($constraintViolationBuilder); - $this->validator->validate('pass', new Password([ - 'contentType' => $contentType, - ])); + $this->validator->validate('pass', new Password( + contentType: $contentType, + )); } /** @@ -212,9 +212,9 @@ public function testKnownValidationErrorsGetRequirementCode( ->with($errorMessage) ->willReturn($constraintViolationBuilder); - $this->validator->validate('pass', new Password([ - 'contentType' => $contentType, - ])); + $this->validator->validate('pass', new Password( + contentType: $contentType, + )); } /** @@ -293,9 +293,9 @@ public function testEveryCoreCharacterRuleErrorProducesRequirementCode(): void ->method('buildViolation') ->willReturn($constraintViolationBuilder); - $this->validator->validate('pass', new Password([ - 'contentType' => $this->createMock(ContentType::class), - ])); + $this->validator->validate('pass', new Password( + contentType: $this->createMock(ContentType::class), + )); } /**