Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registration Failed after rewriting only User Entity #156

Open
BlackScorp opened this issue Aug 22, 2022 · 0 comments
Open

Registration Failed after rewriting only User Entity #156

BlackScorp opened this issue Aug 22, 2022 · 0 comments

Comments

@BlackScorp
Copy link

BlackScorp commented Aug 22, 2022

Q A
Bug? yes
New Feature? no
Community Bundle Version 2.0.x-dev
Sulu Version 2.5.x-dev
Browser Version Browser name and version

Actual Behavior

When you follow this tutorial and overwrite ONLY the user entity
https://docs.sulu.io/en/2.4/cookbook/extend-entities.html
everything works fine until you register. when you create a new account you will see an error:

Expected value of type "App\Entity\User" for association field "Sulu\Bundle\SecurityBundle\Entity\UserRole#$user", got "Sulu\Bundle\SecurityBundle\Entity\User" instead.

it seems like the default user role still use the Sulu User class instead of the overwritte one

Expected Behavior

User Role should use the model defined in sulu_security.yaml

Steps to Reproduce

Code Example is here: https://github.com/OpenTribes/Framework/

Possible Solutions

in the class vendor/sulu/community-bundle/Form/Type/RegistrationType.php

in configureOptions there is a default UserEntity used.

in order to fix this behavoir i replaced empty_data with

    public function configureOptions(OptionsResolver $resolver): void
    {

        $resolver->setDefaults(
            [
                'data_class' => UserInterface::class,
                'validation_groups' => ['registration'],
                'empty_data' => function (FormInterface $form) {
                    $user = new \App\Entity\User();
                    $user->setContact(new Contact());

                    return $user;
                },
            ]
        );
    }

and this way the registration works. i assume a UserEntityFactory could be use here somehow to get the overwritten entity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant