{"action":"opened","issue":{"url":"https://api.github.com/repos/PUGX/PUGXMultiUserBundle/issues/93","labels_url":"https://api.github.com/repos/PUGX/PUGXMultiUserBundle/issues/93/labels{/name}","comments_url":"https://api.github.com/repos/PUGX/PUGXMultiUserBundle/issues/93/comments","events_url":"https://api.github.com/repos/PUGX/PUGXMultiUserBundle/issues/93/events","html_url":"https://github.com/PUGX/PUGXMultiUserBundle/issues/93","id":113381947,"number":93,"title":"A method to add options to registration, profile forms","user":{"login":"truckee","id":2782760,"avatar_url":"https://avatars.githubusercontent.com/u/2782760?v=3","gravatar_id":"","url":"https://api.github.com/users/truckee","html_url":"https://github.com/truckee","followers_url":"https://api.github.com/users/truckee/followers","following_url":"https://api.github.com/users/truckee/following{/other_user}","gists_url":"https://api.github.com/users/truckee/gists{/gist_id}","starred_url":"https://api.github.com/users/truckee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/truckee/subscriptions","organizations_url":"https://api.github.com/users/truckee/orgs","repos_url":"https://api.github.com/users/truckee/repos","events_url":"https://api.github.com/users/truckee/events{/privacy}","received_events_url":"https://api.github.com/users/truckee/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-10-26T15:33:48Z","updated_at":"2015-10-26T15:33:48Z","closed_at":null,"body":"In [this fork](https://github.com/truckee/PUGXMultiUserBundle) there is a method to add an array of options to both registration and profile forms.  Testing the method is, however, currently outside of my skill set.  I'd appreciate some pointers. Functionally these modifications satisfy the requirement of adding options to templates.\r\n\r\nAn example of how the method is used in a form:\r\n````\r\n\r\n        $builder->addEventListener(FormEvents::PRE_SET_DATA,\r\n            function (FormEvent $event) {\r\n            $form = $event->getForm();\r\n            if ($this->options['skill_required']) {\r\n                $form->add('skills', 'skills');\r\n            };\r\n            if ($this->options['focus_required']) {\r\n                $form->add('focuses', 'focuses');\r\n            };\r\n        });\r\n````\r\n\r\nHere's an outline of the method:\r\n\r\n*  Add `options:` to `pugx_multi_user: user:`. Example:\r\n````\r\npugx_multi_user:\r\n  users:\r\n    volunteer:\r\n        options: \r\n            skill_required: true\r\n            focus_required: false\r\n````\r\n* Add `options` parameter to `PUGX\\MultiUserBundle\\DependencyInjection\\Configuration`:\r\n````\r\n        $rootNode->\r\n                children()\r\n                    ->arrayNode('users')->prototype('array')\r\n\t\t\t\t\t\t...\r\n                        ->children()\r\n                            ->arrayNode('options')\r\n                                ->prototype('scalar')->defaultValue(null)->end()\r\n                            ->end()\r\n                        ->end()\r\n````\r\n* add services:\r\n````\r\n\r\n    pugx_multi_user.registration.form.type:\r\n        class: PUGX\\MultiUserBundle\\Form\\RegistrationFormType\r\n        arguments: [%fos_user.model.user.class%]\r\n        tags:\r\n            - { name: form.type, alias: fos_user_registration }        \r\n\r\n    pugx_multi_user.profile.form.type:\r\n        class: PUGX\\MultiUserBundle\\Form\\ProfileFormType\r\n        arguments: [%fos_user.model.user.class%]\r\n        tags:\r\n            - { name: form.type, alias: fos_user_profile }        \r\n````\r\n* Incorporate services in `PUGX\\MultiUserBundle\\DependencyInjection\\Compiler\\OverrideServiceCompilerPass`:\r\n````\r\n        $this->changeService(\r\n                $container,\r\n                'fos_user.registration.form.type',\r\n                'pugx_multi_user.registration.form.type');\r\n\r\n        $this->changeService(\r\n                $container,\r\n                'fos_user.profile.form.type',\r\n                'pugx_multi_user.profile.form.type');\r\n````\r\n* modify `PUGX\\MultiUserBundle\\Model\\UserDiscriminator`:\r\n````    \r\nprotected function buildConfig(array $users)\r\n    {\r\n\t\t...\r\n            $this->conf[$class] = array(\r\n\t\t\t\t\t...\r\n                    'options' => $user['options']\r\n                );\r\n        }\r\n````\r\nand\r\n````\r\n    public function getFormType($name)\r\n    {\r\n        $class = $this->getClass();\r\n        $className = $this->conf[$class][$name]['form']['type'];\r\n        $options = $this->conf[$class]['options'];    //added\r\n        \r\n        if (!class_exists($className)) {\r\n            throw new \\InvalidArgumentException(sprintf('UserDiscriminator, error getting form type : \"%s\" not found', $className));\r\n        }\r\n\r\n        $type = new $className($class, $options);    //parameter added\r\n        return $type;\r\n    }\r\n````\r\n* copy in FOSUserBundle Registration & Profile forms and modify each:\r\n````\r\n    private $class;\r\n    protected $options;\r\n\r\n    /**\r\n     * @param string $class The User class name\r\n     */\r\n    public function __construct($class, $options = null)\r\n    {\r\n        $this->class = $class;\r\n        $this->options = $options;\r\n    }\r\n````"}}