Search code examples
symfonyfosuserbundlepugxmultiuserbundle

Symfony PUGX Bundle - Passing custom variables


I use PUGX Bundle for managing my users.

I want simply pass to the registration template, somes custom variables, but I don't know how to do !

Here the code of the controller :

/**
* @Route("/register", name="company_registration")
*/
public function registrationCompanyAction(Request $request)
{

     return $this->container
        ->get('pugx_multi_user.registration_manager')
        ->register('AppBundle\Entity\Company');
}

Where can I do ?


Solution

  • Custom variables can be rendered in templates if they are defined in the form type shown in config.yml, e.g.,

    config.yml

    ...
    pugx_multi_user:
      users:
        staff:
            entity: 
              class: Truckee\MatchingBundle\Entity\Staff
    #          factory: 
            registration:
              form: 
                type: Truckee\UserBundle\Form\StaffFormType
                name: staff_registration
                validation_groups:  [Registration, Default]
              template: TruckeeUserBundle:Staff:staff.form.html.twig
    

    Form type

    class StaffFormType extends BaseType
    {
    
        public function buildForm(FormBuilderInterface $builder, array $options)
        {
            parent::buildForm($builder, $options);
    
            $builder
                    ->add('organization', new OrganizationType())
            ;
        }
    
        public function getName()
        {
            return 'staff_registration';
        }
    ...
    }
    

    staff form template

    {% block content %}
        <h4 onclick="orghelp();" title="Click for help">{{label_info('Staff Registration Form <span class="glyphicon glyphicon-question-sign"></span>') }}</h4>
        <div id="dialog"><style>.ui-dialog-titlebar-close {
                    display: none;
                }</style></div>    
                {% block fos_user_content %}
                    {% include 'TruckeeUserBundle:Staff:staff_content.html.twig' %}
                {% endblock fos_user_content %}
            {% endblock %}
    

    content template

    {% trans_default_domain 'FOSUserBundle' %}
    
    <form action="{{ path('staff_registration') }}" method="POST" class="form-inline">
        {%if form._token is defined %}{{ form_widget(form._token) }}{% endif %}
        {{ bootstrap_set_style('form-inline') }}
        {% include "TruckeeUserBundle:Person:person_manage.html.twig" %}
        <p><strong>Organization</strong></p>
        <div id="orgNotice"></div>
        {% set staff = form %}
        {% set form = form.organization %}
        <div id="orgForm">
            {% include "TruckeeMatchingBundle:Organization:orgForm.html.twig" %}
            <div>
                {{ bootstrap_set_style('') }}
                {% set form = staff %}
                {{ form_widget(form.save) }}
            </div>
        </div>
    </form>