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

Pugx edit profile #117

Open
darlington72 opened this issue Aug 20, 2016 · 7 comments
Open

Pugx edit profile #117

darlington72 opened this issue Aug 20, 2016 · 7 comments
Labels

Comments

@darlington72
Copy link

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
Copy link
Member

garak commented Aug 21, 2016

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.

@garak garak added the question label Aug 21, 2016
@darlington72
Copy link
Author

darlington72 commented Aug 21, 2016

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
Copy link
Member

garak commented Aug 22, 2016

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

@darlington72
Copy link
Author

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

@garak
Copy link
Member

garak commented Aug 23, 2016

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
Copy link

Muspi commented Jul 26, 2017

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
Copy link

MaximStrutinskiy commented Nov 20, 2017

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;


/**
 * Class FormProfileManagerEditInfoType
 * @package MainBundle\Form\FOSUser
 */
class FormProfileManagerEditInfoType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add(
                'name',
                TextType::class,
                [
                    'required' => true,
                    'label' => 'Имя',
                ]
            )
            ->add(
                'soname',
                TextType::class,
                [
                    'required' => true,
                    'label' => 'Фамилия',
                ]
            )
            ->add(
                'patronymic',
                TextType::class,
                [
                    'required' => true,
                    'label' => 'Отчество',
                ]
            )
            ->add(
                'phone',
                IntegerType::class,
                [
                    'required' => true,
                    'label' => 'Телефон',
                ]
            )
            ->add(
                'address',
                TextType::class,
                [
                    'required' => false,
                    'label' => 'Адрес',
                ]
            );
    }

    /**
     * @param OptionsResolver $resolver
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(
            [
                'data_class' => 'MainBundle\Entity\User',
            ]
        );
    }

    /**
     * @return string
     */
    public function getBlockPrefix()
    {
        return 'app_manager_profile_edit';
    }
}
```

Maybe someone will find this information useful.

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

4 participants