El problema es que siguiendo la guía algo debo hacer mal pues creo que no me renderiza el tipo:
Código PHP:
<?php
// src/Brondem/FormBundle/Entity/Expansible.php
namespace BrondemFormBundleEntity;
use DoctrineCommonCollectionsArrayCollection;
class Expansible
{
private $fields;
public function __construct()
{
$this->fields = new ArrayCollection();
}
public function getFields()
{
return $this->fields;
}
public function setFields( $fields )
{
$this->fields = $fields;
}
}
Código PHP:
<?php
// src/Brondem/FormBundle/Form/Type/ExpansibleType.php
namespace BrondemFormBundleFormType;
use SymfonyComponentFormAbstractType;
use SymfonyComponentFormFormBuilderInterface;
use SymfonyComponentOptionsResolverOptionsResolverInterface;
use BrondemFormBundleEntityExpansible;
class ExpansibleType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add( 'fields', 'collection', array(
'type' => $options['type'],
'allow_add' => true,
'allow_delete' => true,
))->add( 'add' , 'button', array( 'label' => $options[ 'add_label'] ) )
->add( 'delete', 'button', array( 'label' => $options['delete_label'] ) );
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$expansible = new Expansible();
$expansible->getFields()->add( null );
$resolver->setDefaults(array(
'type' => 'text',
'add_label' => 'Add',
'delete_label' => 'Delete',
'data_class' => 'Brondem\FormBundle\Entity\Expansible',
'data' => $expansible,
));
}
public function getName()
{
return 'expansible';
}
}
Código PHP:
{# src/Brondem/FormBundle/Resources/views/Form/expansible_widget.html.twig #}
{% block expansible_widget %}
<div>Es una prueba</div>
{% endblock %}
Código PHP:
<?php
// src/Brondem/AdminBundle/Controller/SliceManager.php
namespace BrondemAdminBundleController;
use SymfonyBundleFrameworkBundleControllerController;
//prueba
use BrondemFormBundleEntityExpansible;
use BrondemFormBundleFormTypeExpansibleType;
class SliceManagerController extends Controller
{
function selectSectionAction( Request $request )
{
$form = $this->createForm(new ExpansibleType(), null, array(
'add_label' => 'Añadir',
'delete_label' => 'Quitar',
));
return $this->render('BrondemAdminBundle::test.html.twig', array(
'form' => $form->createView(),
));
}
}
Código PHP:
{# src/Brondem/AdminBundle/Resources/views/test.html.twig #}
{% extends '::base.html.twig' %}
{% form_theme form 'BrondemFormBundle:Form:expansible_widget.html.twig' %}
{% block body %}
{{ form(form) }}
{% endblock %}
¿Qués es lo que falla?
Un saludo!