Symfony 2.7.7 - Form Collection "Notice: Undefined index: pageId" - php

Trying to generate a form in which it will be a collection of Contents, but unfortunately bereave her mistake and do not know how we recover.
Gives me the error
Notice: Undefined index: pageId
500 Internal Server Error - ContextErrorException
Page Entity:
class Page
{
private $id;
private $name;
/**
* #ORM\OneToMany(targetEntity = "PageContent", mappedBy = "pageId")
*/
private $content;
}
PageContent Entity:
class PageContent
{
private $id;
/**
* #ORM\ManyToOne(targetEntity = "Page", inversedBy = "page_content")
* #ORM\JoinColumn(name = "page_id", referencedColumnName = "id", onDelete = "SET NULL")
*/
private $page;
private $name;
}
EditPageContentsType :
<?php
namespace Eteam\SettingsBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class EditPageContentsType extends AbstractType
{
/**
* Returns the name of this type.
*
* #return string The name of this type
*/
public function getName()
{
return 'EditPageContents';
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('pageContentMap')
->add('content', 'collection', array(
'type' => new PageContentType(),
'options' => array(
'required' => false
),
'allow_add' => true
));
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Eteam\PageBundle\Entity\Page',
));
}
}
PageContentType:
<?php
namespace Eteam\SettingsBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class PageContentType extends AbstractType
{
/**
* Returns the name of this type.
*
* #return string The name of this type
*/
public function getName()
{
return 'pageContent';
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', 'text', array(
'label' => 'Test'
))
->add('content')
->add('type')
->add('pageId');
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Eteam\PageBundle\Entity\PageContent',
));
}
}
I will be grateful for your help.
Because of this I'm a beginner here and in Synfony 2, please do not click negatives. Thanks.
P.S.
If you need more information please let me know.

Firstly your annotations are wrong.
Page should be:
* #ORM\OneToMany(targetEntity = "PageContent", mappedBy = "page")
PageContent should be:
* #ORM\ManyToOne(targetEntity = "Page", inversedBy = "content")
mappedBy and inversedBy by are directly related to the property names of the object for the relations and have to be the same.
Secondly as PageContent is a child of Page, you don't need pageId in your PageContentType. This is a better way to do things.
In EditPageContentsType, add the option 'by_reference' => false see here for why
Then change your addContent() method in Page
public function addContent(PageContent $pageContent)
{
$pageContent->setPage($this);
$this->content->add($pageContent);
}
Similar to the addTag example down a little way in this document
This allows you to easily associate Page with PageContent entities. I recommend having a good read of the forms documentation as you will see this sort of thing a lot.

Related

Symfony 2 add dynamic form; values from database

I would like to create a google categories matching(first field categorie from database and second field a user autocomplete field from google categories) form where i have an entity CategoriesConfig :
private $id;
/**
* #var string
*
* #ORM\Column(name="category_site", type="string", length=100)
*/
private $categorySite;
/**
* #var string
*
* #ORM\Column(name="category_google", type="string", length=100)
*/
private $categoryGoogle;
In my Controller i tried this
/**
* #Route("/adminDashboard/categoriesMatching", name="googleShopping_categories")
* #Security("has_role('ROLE_SUPER_ADMIN')")
*/
public function categoriesMatchingAction(Request $request)
{
// create a task and give it some dummy data for this example
$idSite = $this->get('session')->get('_defaultWebSite')->getId();
$categories = $this->getDoctrine()->getRepository('DataSiteBundle:SiteCategory')->findBy(array('IdSite' => $idSite));;
$categories_config = new CategoriesConfig();
//var_dump($categories);exit;
$form = $this->createForm(new CategoriesConfigType($categories), $categories_config);
return $this->render('GoogleShoppingBundle:Default:categoriesMatching.html.twig', array(
'form' => $form->createView()
));
}
And my form type : CategoriesConfigType:
class CategoriesConfigType extends AbstractType
{
/**
* #param FormBuilderInterface $builder
* #param array $options
*/
private $site_categories;
public function __construct ($site_categories) {
$this->site_categories = $site_categories;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
foreach($this->site_categories as $k => $categorie){
$builder
->add('categorySite')
->add('categoryGoogle');
}
}
/**
* #param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Sp\GoogleShoppingBundle\Entity\CategoriesConfig'
));
}
}
I would like to have as many categories rows as row fields(website itecategorie and google categorie)
The result is like that:
Thank you in advance!
Your loop on $this->categories is uneffective, because the elements you add have the same name each time (categorySite and categoryGoogle), so the FormBuilder replaces the form field each time, instead of adding another one.
However, if you want your form to handle a Collection of CategoryConfigs, you need to take a different approach.
1) Create a CategoriesConfigType (as you did), but who is responsible of only a single CategoriesConfig entity
class CategoriesConfigType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('categorySite')
->add('categoryGoogle');
}
/**
* #param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Sp\GoogleShoppingBundle\Entity\CategoriesConfig'
));
}
}
2) Then use CollectionType field to manipulate your form as a whole collection of CategoryConfigTypes:
class YourCollectionType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('categoriesConfigs', CollectionType::class, array(
'entry_type' => CategoriesConfigType::class,
'entry_options' => array('required' => false)
);
}
}

Load options into drop down on a form based on user's id in symfony 2

I have a question for you and to give you some idea of what i'm doing, i will try and explain the idea. I have a system where user's are able to add geckos to a database, when that gecko is added, it saves the user id into a column called user_id - this works perfect and sets me up for what i am trying to achieve now.
I have a system where user's are able to add weight entries for that gecko, problem is, right now it just loads every gecko in the database, not the one's that are specific to that user.
Here is a portion from my Weight.php entity:
/**
* #ORM\ManyToOne(targetEntity="Gecko", inversedBy="weights")
* #ORM\JoinColumn(name="gecko_id", referencedColumnName="id")
*/
private $geckoId;
Which is linked to this part in the Gecko.php:
/**
* #ORM\OneToMany(targetEntity="Weight", mappedBy="geckoId", cascade={"persist", "remove"})
*/
private $weights;
And here is the user part inside Gecko.php entity which links the current user's id to save to the database:
/**
* #ORM\ManyToOne(targetEntity="Breedr\UserBundle\Entity\User", inversedBy="geckos")
* #ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
protected $user;
And the linked part in the User.php entity:
/**
* #ORM\OneToMany(targetEntity="Breedr\GeckoBundle\Entity\Gecko", mappedBy="user", cascade={"persist", "remove"})
*/
protected $geckos;
Now, here is my Weight entities Form (WeightType.php):
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('weighedDate')
->add('weight')
->add('geckoId')
;
}
Which gives you a drop down based on the parts above that look like this:
So what i am now trying to achieve is to ONLY show the geckos that are linked with the current user's ID. What is the best way to achieve this?
Thanks in advance :)
Andy
EDIT:
Here is my WeightType file:
<?php
namespace Breedr\GeckoBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class WeightType extends AbstractType
{
/**
* #param FormBuilderInterface $builder
* #param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('weighedDate')
->add('weight')
->add('geckoId')
;
}
/**
* #param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Breedr\GeckoBundle\Entity\Weight'
));
}
/**
* #return string
*/
public function getName()
{
return 'breedr_geckobundle_weight';
}
}
EDIT 2:
Here is my create form snippet:
private function createCreateForm(Weight $entity)
{
$form = $this->createForm(new WeightType(), $entity, array(
'action' => $this->generateUrl('weight_create'),
'method' => 'POST',
));
$form->add('submit', 'submit', array('label' => 'Create'));
return $form;
}
You must use entity Field Type + query_build option. Thus You can build a custom query in order to filter the results, for instance:
<?php
namespace AppBundle\Form\Type;
use Doctrine\ORM\EntityRepository;
// ...
$builder->add('users', 'entity', array(
'class' => 'AcmeHelloBundle:User',
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('u')
->orderBy('u.username', 'ASC');
},
));
On your specific case your form type might looks like something like this:
<?php
# maybe you need to fix some namespaces...
use Doctrine\ORM\EntityRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class WeightType extends AbstractType
{
/** #var int */
protected $currentUserId;
/**
* param int $currentUserId It can be passed from controller
* when creating form instance
*/
public function __construct($currentUserId)
{
$this->currentUserId = $currentUserId;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$id = $this->currentUserId;
$builder->add('users', 'entity', array(
'class' => 'GeckoBundle:Gecko',
'query_builder' => function (EntityRepository $er) use ($id) {
return $er->createQueryBuilder('g')
->where('user_id = ?')
->setParameter(0, $id);
},
));
}
}
On the controller...
<?php
//...
public function add()
{
$currentUserId = $this->getUser()->getId(); # may be it...
$form = $this->createForm(new WeigthType($currentUserId));
}

Using some dynamic forms related to the same class

Symfony 2.3
I'm embedding some Forms to be able to change each user property related to permissions. I've created an UserAdminType which is displayed for each user in the same page:
<?php
namespace Msalsas\UserAdminBundle\Form;
use Msalsas\UserBundle\Entity\User;
use Msalsas\UserBundle\Entity\ExtendedUser;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormEvent;
class UserAdminType extends AbstractType
{
private $user;
public function __construct(User $user)
{
$this->user = $user;
$this->extendedUser = new ExtendedUser($this->user);
}
/**
* #param FormBuilderInterface $builder
* #param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$extendedUser = $this->extendedUser;
$builder
->add('extendedRole',
'choice', array('choices' => array(
$extendedUser::ROLE_1 => "Role 1",
$extendedUser::ROLE_2 => "Role 2",
$extendedUser::ROLE_3 => "Role 3",
),
'label' => $this->user->getUsername()
))
->add('Change roles for '.$this->user->getUsername(), 'submit')
;
$builder->addEventListener(
FormEvents::POST_SUBMIT,
function (FormEvent $event) {
$form = $event->getForm();
$data = $event->getData();
if( ! $form->getClickedButton('Change roles for '.$this->user->getUsername()) )
{
// Here I should avoid submitting the form
}
}
);
}
/**
* #param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Msalsas\UserBundle\Entity\ExtendedUser',
'empty_data' => function (FormInterface $form) {
return null;
}
));
}
/**
* #return string
*/
public function getName()
{
return 'extendedUserRoleForm';
}
}
The problem is that when I submit one of those forms, all other forms are also submitted, returning an error, because the extendedUser uses a constructor to initialize the object with the User as parameter:
Catchable Fatal Error: Argument 1 passed to Msalsas\UserBundle\Entity\ExtendedUser::__construct() must be an instance of Msalsas\UserBundle\Entity\User, none given, called in .../vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/Type/FormType.php on line 140 and defined
I've also tried to set the empty_data with a new default ExtendedUser:
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Msalsas\UserBundle\Entity\ExtendedUser',
'empty_data' => function (FormInterface $form) {
return $this->extendedUser;
}
));
}
Now, when submitting the form, the new entity is persisted, but the other forms are still submitted, and returning an error: This form should not contain extra fields. This seems to be due to the duplicated property name (extendedRole).
How could I avoid the other forms to be submitted?
I've found out the solution here.
Each Form must have different name. So I've added a $name property, and assigned it in the constructor:
private $user;
private $name = 'default_name_';
private $extendedUser;
public function __construct(User $user, $formName)
{
$this->user = $user;
$this->extendedUser = new ExtendedUser($this->user);
$this->name = $this->name.$formName;
}
//... (No event required)
/**
* #return string
*/
public function getName()
{
return $this->name;
}
The $formName parameter is relative to the current user. In this way, only the "clicked" form is submitted. Wish it helps.

Symfony2 Registration form with only single record of collection field

So I'm trying to create a registration form in Symfony 2 which contains my "Person" entity. The person entity has a one-to-many join, and I want the registration form to allow the user to select a single instance of this "Many" side of the join.
The structure is Users and Institutions. A user can have many institutions. I want a user to select a single institution at registration time (but the model allows for more later).
The basic structure is:
RegistrationType -> PersonType -> PersonInstitutionType
…with corresponding models:
Registration (simple model) -> Person (doctrine entity) -> PersonInstitution (doctrine entity, oneToMany relation from Person)
I tried to pre-populate an empty Person & PersonInstitution record in the RegistrationController but it gives me the error:
Expected argument of type "string or Symfony\Component\Form\FormTypeInterface", "TB\CtoBundle\Entity\PersonInstitution" given
(ok above has been fixed).
I've moved the code from my website to here below, trying to remove all the irrelevant bits.
src/TB/CtoBundle/Form/Model/Registration.php
namespace TB\CtoBundle\Form\Model;
use TB\CtoBundle\Entity\Person;
class Registration
{
/**
* #var Person
*/
private $person
private $termsAccepted;
}
src/TB/CtoBundle/Form/RegistrationType.php
namespace TB\CtoBundle\Form;
use TB\CtoBundle\Form\PersonType;
class RegistrationType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('person', new PersonType());
$builder->add('termsAccepted','checkbox');
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'TB\CtoBundle\Form\Model\Registration',
'cascade_validation' => true,
));
}
public function getName()
{
return 'registration';
}
}
src/TB/CtoBundle/Entity/Person.php
namespace TB\CtoBundle\Entity;
use TB\CtoBundle\Entity\PersonInstitution
/**
* #ORM\Entity()
*/
class Person
{
/**
* #var ArrayCollection
* #ORM\OneToMany(targetEntity="PersonInstitution", mappedBy="person", cascade={"persist"})
*/
private $institutions;
}
src/TB/CtoBundle/Form/PersonType.php
namespace TB\CtoBundle\Form;
class PersonType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('institutions', 'collection', array('type' => new PersonInstitutionType()))
;
}
/**
* #param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'TB\CtoBundle\Entity\Person',
));
}
/**
* #return string
*/
public function getName()
{
return 'tb_ctobundle_person';
}
}
src/TB/CtoBundle/Entity/PersonInstitution.php
namespace TB\CtoBundle\Entity
/**
* PersonInstitution
*
* #ORM\Table()
* #ORM\Entity
*/
class PersonInstitution
{
/**
* #ORM\ManyToOne(targetEntity="Person", inversedBy="institutions", cascade={"persist"})
*/
private $person;
/**
* #ORM\ManyToOne(targetEntity="Institution", inversedBy="members")
*/
private $institution;
/**
* #ORM\Column(type="boolean")
*/
private $approved;
}
src/TB/CtoBundle/Form/PersonInstititionType.php
namespace TB\CtoBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class PersonInstitutionType extends AbstractType
{
/**
* #param FormBuilderInterface $builder
* #param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('approved')
->add('person')
->add('institution')
;
}
/**
* #param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'TB\CtoBundle\Entity\PersonInstitution'
));
}
/**
* #return string
*/
public function getName()
{
return 'tb_ctobundle_personinstitution';
}
}
src/TB/CtoBundle/Controller/Registration.php
namespace TB\CtoBundle\Controller;
class RegisterController extends Controller
{
/**
*
* #param Request $request
* #return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
public function registerAction(Request $request)
{
$registration = new Registration;
$person = new Person();
$institution = new PersonInstitution();
$person->addInstitution($institution);
$registration->setPerson($person);
// this causes error:
// Entities passed to the choice field must be managed. Maybe persist them in the entity manager?
// $institution->setPerson($person);
$form = $this->createForm(new RegistrationType(), $registration);
$form->handleRequest($request);
if($form->isValid()) {
$registration = $form->getData();
$person = $registration->getPerson();
// new registration - account status is "pending"
$person->setAccountStatus("P");
// I'd like to get rid of this if possible
// for each "PersonInstitution" record, set the 'person' value
foreach($person->getInstitutions() as $rec) {
$rec->setPerson($person);
}
$em = $this->getDoctrine()->getManager();
$em->persist($person);
$em->flush();
}
return $this->render('TBCtoBundle:Register:register.html.twig', array('form' => $form->createView()));
}
}
Here is a detailed solution for adding an Collection field to Person entity and formType.
Your complex question with Registration entity can be solved with this.
I suggest you to use this 3 entity related connection if it is really needed. (only because of termsAccepted data!?)
If you won't change your opinion, then use this annotation:
Registration code:
use TB\CtoBundle\Entity\Person;
/**
* #ORM\OneToOne(targetEntity="Person")
* #var Person
*/
protected $person;
Person code:
use TB\CtoBundle\Entity\PersonInstitution;
/**
* #ORM\OneToMany(targetEntity="PersonInstitution", mappedBy = "person")
* #var ArrayCollection
*/
private $institutions;
/* I suggest you to define these functions:
setInstitutions(ArrayCollection $institutions),
getInstitutions()
addInstitution(PersonInstitution $institution)
removeInstitution(PersonInstitution $institution)
*/
PersonInstitution code:
use TB\CtoBundle\Entity\Person;
/**
* #ORM\ManyToOne(targetEntity="Person", inversedBy="institutions", cascade={"persist"}))
* #var Person
*/
private $person;
PersonType code:
use TB\CtoBundle\Form\PersonInstitutionType;
->add('institutions', 'collection', array(
'type' => new PersonInstitutionType(), // here is your mistake!
// Other options can be selected here.
//'allow_add' => TRUE,
//'allow_delete' => TRUE,
//'prototype' => TRUE,
//'by_reference' => FALSE,
));
PersonController code:
use TB\CtoBundle\Entity\Person;
use TB\CtoBundle\Entity\PersonInstitution;
/**
* ...
*/
public funtcion newAction()
{
$person = new Person;
$institution = new PersonInstitution;
$institution->setPerson($person);
$person->addInstitution($institution);
$form = $this->createForm(new PersonType($), $person); // you can use formFactory too.
// If institution field is required, then you have to check,
// that is there any institution able to chose in the form by the user.
// Might you can redirect to institution newAction in that case.
return array( '...' => $others, 'form' => $form);
}
If you need more help in twig code, then ask for it.

Using model for unmapped web forms (form types)

I want to handle all validations with #Assert so I'm using Models for my web forms (Form Type) which are not mapped to database. The question I have is, is it an acceptable practise in Symfony world?
I know that one disadvantage of this way is not being able to automatically generate setters and getters. I read up on it but didn't get a clear picture so that's why I'm asking.
A rough example:
LoginType.php
namespace User\RecordBundle\Resources\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class LoginType extends AbstractType
{
/**
* #param FormBuilderInterface $builder
* #param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->setAction($options['action'])
->setMethod('POST')
->add('username', 'text', array('label' => 'Username'))
->add('button', 'submit', array('label' => 'Login'));
}
/**
* #param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array('data_class' => 'User\RecordBundle\Entity\UserEntity'));
}
/**
* Returns the name of this type.
*
* #return string The name of this type
*/
public function getName()
{
return 'login';
}
}
LoginModel.php
namespace User\RecordBundle\Resources\Form\Model;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Class LoginModel
* Mapped to Login form
*
* #package User\RecordBundle\Resources\Form\Model
*/
class LoginModel
{
/**
* #Assert\NotBlank(message = "The Username field should not be blank.")
*
* #var string $username
*/
protected $username;
/**
* #return string $username
*/
public function getUsername()
{
return $this->username;
}
/**
* #param string $username
* #return $this
*/
public function setUsername($username)
{
$this->username = $username;
return $this;
}
}
This case: your FormType is not related to any Entity, must be rare in a well planned application. So rarely Model with FormType solution can be used, I don't have any objections to it. Remark: Specifically for User handling I recommend you to use friends of symfony created: FOS\UserBundle\FOSUserBundle().
You said that you're new in Symfony, so I summarized here the general practice of making a Form, which is related to an Entity and user will be available to fill some part of it.
class code:
class Entity
{
/**
* #Assert\NotBlank(message = "The data is empty.")
*/
private $data;
}
form type code:
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Doctrine\ORM\EntityRepository;
class EntityType extends AbstractType
{
/**
* #var \Doctrine\Common\Persistence\ObjectManager
*/
protected $om;
protected $admin;
protected $edit;
public function __construct($om, $admin = false, $new = false)
{
$this->om = $om;
$this->admin = $admin;
$this->new = $;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
// You can show specific parts of the Entity for the admin to fill and reduced group of fields for the common user.
// You can set specific behaviour in case of creation and editing.
// You can add a collection type field, and select specific entities with ObjectManager. To make your form more flexible.
$builder
->add('data', 'text', array(
'label' => 'Data text',
'label_attr' => array(
'class' => 'reqfield'
),
'attr' => array(
'class' => 'css-class-of-the-field'
'...' => $etc,
))
// You don't need to add submit button
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Application\EntityBundle\Entity\Entity'
));
}
public function getName()
{
return 'application_entity_bundle_entity';
}
}
// Actions like: new and edit, can use your formType above.

Categories