Closed
Description
Symfony version(s) affected
6.2.5
Description
PasswordHasherListener
class must take into account an AbstractType
class when it's parent is a RepeatedType
.
How to reproduce
I have created an AbstractType to use for repeat password:
class RepeatPasswordType extends AbstractType
{
public function getParent(): ?string
{
return RepeatedType::class;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'mapped' => false,
'type' => PasswordType::class,
// ....
'first_options' => ([
'hash_property_path' => 'password',
// ....
],
]};
}
}
When submitting the form, the PasswordHasherListener
service cannot detect that my type is a RepeatedType
class.
Possible Solution
Maybe we can create a function to detect this case:
private function isRepeatedType(?FormInterface $parentForm): bool
{
if (null === $parentForm) {
return false;
}
$innerType = $parentForm->getConfig()->getType()->getInnerType();
return $innerType instanceof RepeatedType ||
($innerType instanceof AbstractType && RepeatedType::class === $innerType->getParent());
}
And use it in the registerPassword function:
public function registerPassword(FormEvent $event): void
{
// ....
if ($this->isRepeatedType($parentForm)) {
$mapped = $parentForm->getConfig()->getMapped();
$parentForm = $parentForm->getParent();
}
// ....
}
Additional Context
No response