Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

PasswordHasherListener does not take into account of AbstractType #49260

Copy link
Copy link
Closed
@laurentmuller

Description

@laurentmuller
Issue body actions

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.