PUGX / PUGXMultiUserBundle

An extension for FOSUserBundle to handle users of different types. Compatible with Doctrine ORM.
163 stars 96 forks source link

Pugx edit profile #117

Open darlington72 opened 7 years ago

darlington72 commented 7 years ago

Hello everyone!

Thank you for this bundle which is very useful!

Thanks to this bundle, I designed two kind of account and it perfectly works to creating it. But I don't succeed in editing profile. Could you help me with an example code, like the documentation, to allow users edit their profiles?

Thanks a lot!

garak commented 7 years ago

Hi, thanks for asking. Unfortunately, this is not a support forum. If you provide a working example with the expected behaviour and the actual behaviour, we can try to identify your problem. Otherwise, this issue will be closed.

darlington72 commented 7 years ago

Hi Garak, I'm sorry for this mistake.. Thanks for your answe, here is my issue:

I wanted to add "edit profile" exactly like registration with pugx bundle like this: (config.yml) `pugx_multi_user: users: user_etudiant: entity: class: AP\UserBundle\Entity\Etudiant registration: ... profile: form: type: AP\UserBundle\Form\Type\ProfileEtudiantFormType name: fos_user_etudiant_edit_profile validation_groups: [Profile, Default]

user_representant:
    entity:
      class: AP\UserBundle\Entity\Representant
    registration:
      form:
       ...
   profile:
      form:
        type: AP\UserBundle\Form\Type\ProfileRepresentantFormType
        name: fos_user_representant_profile
        validation_groups:  [Profile, Default]`

So paths are directly connected to respective FormType. This is okay, but when I try to modify different fields, they are not update...

Have you got any idea?

Thank you!

garak commented 7 years ago

What is the meaning of "they are not update"?

darlington72 commented 7 years ago

For example, the field "address" of "user_representant" which is not updated in my database

garak commented 7 years ago

This is a partial information, you should go deep and debug it. Is your form valid? The queries you expect are not performed or performed wrongly? Etc.

Muspi commented 7 years ago

Hello, try to override ProfileController of FOSUser like this, it worked for me:

use FOS\UserBundle\Controller\ProfileController as BaseControler;

class ProfileController extends BaseControler
{
    public function editAction(Request $request)
    {
            $user = $this->getUser();
            return $this->container
                ->get('pugx_multi_user.profile_manager')
                ->edit(get_class($user));
    }
}

As result, I have the good form and template defined in pugx_multi_user configuration.

MaximStrutinskiy commented 6 years ago

I have another solution

pugx_multi_user:
    users:
        manager:
            entity:
                class: MainBundle\Entity\Manager
            registration:
                form:
                    type: MainBundle\Form\FOSUser\FormManagerRegistrationType
                    name: app_user_manager_registration
                    validation_groups:  [Registration, Default]
            profile:
                form:
                    type: MainBundle\Form\FOSUser\FormProfileManagerEditInfoType
                    name: app_manager_profile_edit
                    validation_groups:  [Profile, Default]
        customer:
            entity:
                class: MainBundle\Entity\Customer
            registration:
                form:
                    type: MainBundle\Form\FOSUser\FormCustomerRegistrationType
                    name: app_user_customer_registration
                    validation_groups:  [Registration, Default]
            profile:
                form:
                    type: MainBundle\Form\FOSUser\FormProfileCustomerEditInfoType
                    name: app_customer_profile_edit
                    validation_groups:  [Profile, Default]
`

Hear, you can add you'r custom/personal form to One of you user User types:

pugx_multi_user:
    users:
        manager:
            profile:
                form:
                    type: MainBundle\Form\FOSUser\FormProfileManagerEditInfoType
                    name: app_manager_profile_edit
                    validation_groups:  [Profile, Default]
````**Example form**

<?php namespace MainBundle\Form\FOSUser;

use Symfony\Component\Form\Extension\Core\Type\IntegerType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver;

/**

Maybe someone will find this information useful.