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

OVERRIDE DEFAULT REGISTRATION TEMPLATE #151

Open
ALECSQY opened this issue May 24, 2017 · 5 comments
Open

OVERRIDE DEFAULT REGISTRATION TEMPLATE #151

ALECSQY opened this issue May 24, 2017 · 5 comments
Labels

Comments

@ALECSQY
Copy link

ALECSQY commented May 24, 2017

Hello,

I install PUGXMultiUserBundle and I want, to register two different classes of users, use two different templates. But instead, I have just my layout without any form in my template. If I override the register.html.twig from FOS, it's OK but I can't use it for my two different users - Customer and Company. Where I am wrong ?

Here's my config :

pugx_multi_user:
  users:
    Customer:
        entity: 
          class: UserBundle\Entity\Customer
#          factory: 
        registration:
          form: 
            type: UserBundle\Form\Type\RegistrationCustomerFormType
            name: fos_user_registration
            validation_groups:  [Registration, Default]
          template: UserBundle:Registration:registerCustomer.html.twig
        profile:
          form:
            type: UserBundle\Form\Type\ProfileCustomerFormType
            name: fos_user_profile_form
            validation_groups:  [Profile, Default] 
    Company:
        entity: 
          class: UserBundle\Entity\Company
        registration:
          form: 
            type: UserBundle\Form\Type\RegistrationCompanyFormType
            name: fos_user_registration_company
          template: UserBundle:Registration:registerCompany.html.twig
        profile:
          form: 
            type: UserBundle\Form\Type\RegistrationCompanyFormType

It's my forms:

class RegistrationCompanyFormType extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder           
            ->add('name', TextType::class, array('label'=>'Raison sociale',
                                                      'attr'=>['class'=>'form-control']))
            ->add('adress', TextType::class, array('label'=>'Adresse',
                                                      'attr'=>['class'=>'form-control']))
            ->add('city', TextType::class, array('label'=>'Ville',
                                                      'attr'=>['class'=>'form-control']))
            ->add('postcode', TextType::class, array('label'=>'Code Postal',
                                                      'attr'=>['class'=>'form-control']))
            ->add('phone', TextType::class, array('label'=>'Téléphone',
                                                      'attr'=>['class'=>'form-control']))
            ->add('skill', TextType::class, array('label'=>'Métier',
                                                      'attr'=>['class'=>'form-control']))
            ->add('email', LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\EmailType'), array('label' => 'Mail'))
            ->add('website', TextType::class, array('label'=>'Site internet',
                                                    'attr'=>['class'=>'form-control']))
            ->add('username', null, array('label' => 'Nom d\'utilisateur'))
            ->add('plainPassword', LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\RepeatedType'), array(
                'type' => LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\PasswordType'),
                'options' => array('translation_domain' => 'FOSUserBundle'),
                'first_options' => array('label' => 'Mot de passe'),
                'second_options' => array('label' => 'Confirmez votre mot de passe'),
                'invalid_message' => 'Les mots de passe ne correspondent pas !',
            ))
        ;
    }

    /**
     * {@inheritdoc}
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'UserBundle\Entity\Company',
            'csrf_token_id' => 'registration',
            // BC for SF < 2.8
            'intention' => 'registration',
        ));
    }

    // BC for SF < 3.0
    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return $this->getBlockPrefix();
    }

    /**
     * {@inheritdoc}
     */
    public function getBlockPrefix()
    {
        return 'fos_user_registration_company';
    }
class RegistrationCustomerFormType extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('firstname', TextType::class, array('label'=>'Prénom',
                                                      'attr'=>['class'=>'form-control']))
            ->add('lastname', TextType::class, array('label'=>'Nom',
                                                      'attr'=>['class'=>'form-control']))
            ->add('adress', TextType::class, array('label'=>'Adresse',
                                                      'attr'=>['class'=>'form-control']))
            ->add('city', TextType::class, array('label'=>'Ville',
                                                      'attr'=>['class'=>'form-control']))
            ->add('postcode', TextType::class, array('label'=>'Code Postal',
                                                      'attr'=>['class'=>'form-control']))
            ->add('phone', TextType::class, array('label'=>'Téléphone',
                                                      'attr'=>['class'=>'form-control']))
            ->add('email', LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\EmailType'), array('label' => 'Mail'))
            ->add('username', null, array('label' => 'Nom d\'utilisateur'))
            ->add('plainPassword', LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\RepeatedType'), array(
                'type' => LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\PasswordType'),
                'options' => array('translation_domain' => 'FOSUserBundle'),
                'first_options' => array('label' => 'Mot de passe'),
                'second_options' => array('label' => 'Confirmez votre mot de passe'),
                'invalid_message' => 'Les mots de passe ne correspondent pas !',
            ))
        ;
    }

    /**
     * {@inheritdoc}
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'UserBundle\Entity\Customer',
            'csrf_token_id' => 'registration',
            // BC for SF < 2.8
            'intention' => 'registration',
        ));
    }

    // BC for SF < 3.0
    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return $this->getBlockPrefix();
    }

    /**
     * {@inheritdoc}
     */
    public function getBlockPrefix()
    {
        return 'fos_user_registration';
    }

My controllers

class RegistrationCompanyController extends Controller
{
    public function registerAction()
    {
        return $this->container
                    ->get('pugx_multi_user.registration_manager')
                    ->register('UserBundle\Entity\Company');
    }
}

class RegistrationCustomerController extends Controller
{
    public function registerAction()
    {
        return $this->container
                    ->get('pugx_multi_user.registration_manager')
                    ->register('UserBundle\Entity\Customer');
    }
}

My templates: for Company

{% extends "::base.html.twig" %}

	{% block body %}

		<div style="background-color:white;">
			{% block fos_user_content %}
			    {% trans_default_domain 'FOSUserBundle' %}

			    <form action="{{ path('company_registration') }}"  method="POST">
			        {{ form(form) }}
			        <div>
			            <input type="submit" value="Enregistrez votre société" />
			        </div>
			    </form>
			{% endblock fos_user_content %}
		</div>

	{% endblock %}

For Customer:

{% extends "::base.html.twig" %}
	
	{% block body %}

		<div style="background-color:white;">

			{% block fos_user_content %}
			    {% trans_default_domain 'FOSUserBundle' %}

			    <form action="{{ path('customer_registration') }}"  method="POST">
			        {{ form_widget(form) }}
			        <div>
			            <input type="submit" value="Créez votre compte" />
			        </div>
			    </form>
			{% endblock fos_user_content %}

		</div>

	{% endblock %}

Any help please ?

@garak garak added the question label May 24, 2017
@Cryde
Copy link

Cryde commented May 24, 2017

I have the same issue since I updated the bundle :)
Try to install it from commit (in your composer) :
"pugx/multi-user-bundle": "dev-master#e0af577b221ca74e07a09629f5617bb2a152ce53",

It worked for me :)

@ALECSQY
Copy link
Author

ALECSQY commented May 24, 2017

Thanks a lot. But I have this error when i run this command :
php composer.phar require "pugx/multi-user-bundle" : "dev-master#e0af577b221ca74e07a09629f5617bb2a152ce53"

[InvalidArgumentException]
Could not find package dev-master#e0af577b221ca74e07a09629f5617bb2a152ce53 at any version for your minimum-stabilit
y (stable). Check the package spelling or your minimum-stability

@ALECSQY
Copy link
Author

ALECSQY commented May 24, 2017

I succeed now !!! THANKS THANKS !!! During 2 days I was blocked and desperate. It's marvellous.
Thanks again, it's wonderfull !

@wojoj93
Copy link

wojoj93 commented Jul 2, 2017

I have the same issues. I can't update composer because I have a problem with "minimum-stability (stable)"

ldesmeules referenced this issue Jul 13, 2017
* Fix in response return

Without this fix only RedirectResponse can be returned. In my project I send response by JsonRespons and I had to make this fix.
@MarwenBenTalebAli
Copy link

MarwenBenTalebAli commented Sep 6, 2017

Hello,
Im trying to do the same exemple.
Im getting for user one :
UserDiscriminator, error getting form type : "GE\CandidatBundle\Form\Type\CandidatType" not found

and for user two:
UserDiscriminator, error getting form type : "GE\CandidatBundle\Form\Type\EmployeurType" not found

How to override register fosuserbundle template to be functional with PUGXMultiUserBundle?

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

No branches or pull requests

5 participants