Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

overriding registration FOSUserBundle Symfony2

Tags:

symfony

I am trying to override Registration Form in FOSUserBundle but i get this error: i have followed this tutorial in the official documentation: Link

Could not load type "uae_user_registration"

My files are: services.yml

# src/Uae/UserBundle/Resources/config/services.yml 
services:
    uae_user.registration.form.type:
        class: Uae\UserBundle\Form\Type\RegistrationFormType
        arguments: [%fos_user.model.user.class%]
        tags:
        - { name: form.type, alias: uae_user_registration }

config.yml:

app/config/config.yml

fos_user:
    db_driver:     orm                         
    firewall_name: main                       
    user_class:    Uae\UserBundle\Entity\User 
    registration:
            form:
                type: uae_user_registration

RegistrationFormType:

<?php
#src/Uae/UserBundle/Form/Type/RegistrationType.php

namespace Uae\UserBundle\Form\Type;

use Symfony\Component\Form\FormBuilderInterface;
use FOS\UserBundle\Form\Type\RegistrationFormType as BaseType;

class RegistrationFormType extends BaseType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
    parent::buildForm($builder, $options);

    // add your custom field
    $builder->add('nom');
    $builder->add('prenom');
}

public function getName()
{
    return 'uae_user_registration';
}
}
like image 444
Akrramo Avatar asked Dec 06 '22 14:12

Akrramo


2 Answers

i solved my problem: i just imported the new service that i created in the config file app\config\config.yml

imports:
    - { resource: @UaeUserBundle/Resources/config/services.yml }
like image 138
Akrramo Avatar answered Dec 10 '22 21:12

Akrramo


The reason you're getting the error is because you do not have a DependencyInjection for your specific bundle. The program doesn't know where to look for your services.yml file.

You need an UaeUserExtension.php and Configuration.php inside your DependencyInjection folder under your User Bundle.

The easy solution to this is to generate the bundle via app/console generate:bundle. This way, it'll create your DependencyInjection for you automatically.

The manual solution would be to create a DependencyInjection folder inside your Uae/UserBundle. Inside DependencyInjection, create a file called Configuration.php and place the contents below:

<?php

namespace Uae\UserBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
{
    /**
     * {@inheritDoc}
     */
    public function getConfigTreeBuilder()
    {
        $treeBuilder = new TreeBuilder();
        $rootNode = $treeBuilder->root('uae_user');

        return $treeBuilder;
    }
}

And create a file called UaeUserExtension.php inside the same directory and place these contents inside:

<?php

namespace Uae\UserBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

class EnergyUserExtension extends Extension
{
    /**
     * {@inheritDoc}
     */
    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);

        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('services.yml');
    }
}
like image 25
Hyunmin Kim Avatar answered Dec 10 '22 21:12

Hyunmin Kim