public function configure() { $project = $this->getData(); $this->addRequiredOption('entity_manager'); $em = $this->getOption('entity_manager'); $this->add(new TextField('name')); $statusTransformer = new EntityToIDTransformer(array('em' => $em, 'className' => 'Application\\ChiaBundle\\Entity\\Status')); $statusField = new ChoiceField('status', array('choices' => $em->getRepository('Application\\ChiaBundle\\Entity\\Status')->getStatusOptions())); $statusField->setValueTransformer($statusTransformer); $this->add($statusField); $contactTransformer = new EntityToIDTransformer(array('em' => $em, 'className' => 'Application\\ChiaBundle\\Entity\\Contact')); $contactField = new AutocompleteField('contact', array('choices' => $em->getRepository('Application\\ChiaBundle\\Entity\\Contact')->getCompanyOptions())); $contactField->setValueTransformer($contactTransformer); $this->add($contactField); $userTransformer = new EntityToIDTransformer(array('em' => $em, 'className' => 'Application\\ChiaBundle\\Entity\\User')); $ownerField = new ChoiceField('owner', array('choices' => $em->getRepository('Application\\ChiaBundle\\Entity\\User')->getUserOptions())); $ownerField->setValueTransformer($userTransformer); $this->add($ownerField); $this->add(new TextareaField('description')); $this->add(new MoneyField('price')); $this->add(new ChoiceField('price_type', array('choices' => Project::$price_types))); $this->add(new DateField('estimated_start_date')); $this->add(new DateField('estimated_end_date')); $categoryTransformer = new EntityToIDTransformer(array('em' => $em, 'className' => 'Application\\ChiaBundle\\Entity\\Category')); $categoryField = new ChoiceField('category', array('choices' => $em->getRepository('Application\\ChiaBundle\\Entity\\Category')->getCategoryOptions(), 'empty_value' => 'Select a category...')); $categoryField->setValueTransformer($categoryTransformer); $this->add($categoryField); }
public function configure() { $contact = $this->getData(); $this->addOption('company_choices'); $this->addRequiredOption('entity_manager'); $em = $this->getOption('entity_manager'); $this->add(new TextField('name')); if ($contact->getType() == 1) { $this->add(new TextField('title')); $this->addRequiredOption('company_choices'); $contactTransformer = new EntityToIDTransformer(array('em' => $em, 'className' => 'Application\\ChiaBundle\\Entity\\Contact')); $companyField = new AutocompleteField('company', array('choices' => $this->getOption('company_choices'))); $companyField->setValueTransformer($contactTransformer); $this->add($companyField); } $this->add(new TextField('code')); $this->add(new TextareaField('description')); // phone $phonesTransformer = new CollectionToGroupTransformer(array('em' => $em, 'fields' => array('number'), 'className' => 'Application\\ChiaBundle\\Entity\\Phonenumber', 'create_instance_callback' => function () use($contact, $em) { $phone = new Phonenumber(); $contact->addPhonenumbers($phone); $phone->setContact($contact); $em->persist($phone); return $phone; }, 'remove_instance_callback' => function ($phone) use($contact, $em) { $contact->getPhonenumbers()->removeElement($phone); $em->remove($phone); })); $phoneGroup = new FieldGroup('phonenumbers'); $phoneGroup->add(new TextField('number')); $phones = new CollectionField($phoneGroup, array('modifiable' => true)); $phones->setValueTransformer($phonesTransformer); $this->add($phones); // email $emailsTransformer = new CollectionToGroupTransformer(array('em' => $em, 'fields' => array('email'), 'className' => 'Application\\ChiaBundle\\Entity\\Email', 'create_instance_callback' => function () use($contact, $em) { $email = new Email(); $contact->addEmails($email); $email->setContact($contact); $em->persist($email); return $email; }, 'remove_instance_callback' => function ($email) use($contact, $em) { $contact->getEmails()->removeElement($email); $em->remove($email); })); $emailGroup = new FieldGroup('emails'); $emailGroup->add(new TextField('email')); $emails = new CollectionField($emailGroup, array('modifiable' => true)); $emails->setValueTransformer($emailsTransformer); $this->add($emails); // address $addressesTransformer = new CollectionToGroupTransformer(array('em' => $em, 'fields' => array('address', 'city', 'state', 'country', 'postal_code'), 'className' => 'Application\\ChiaBundle\\Entity\\Address', 'create_instance_callback' => function () use($contact, $em) { $address = new Address(); $contact->addAddresses($address); $address->setContact($contact); $em->persist($address); return $address; }, 'remove_instance_callback' => function ($address) use($contact, $em) { $contact->getAddresses()->removeElement($address); $em->remove($address); })); $addressGroup = new FieldGroup('addresses'); $addressGroup->add(new TextareaField('address')); $addressGroup->add(new TextField('city')); $addressGroup->add(new TextField('state')); $addressGroup->add(new CountryField('country')); $addressGroup->add(new TextField('postal_code')); $addresses = new CollectionField($addressGroup, array('modifiable' => true)); $addresses->setValueTransformer($addressesTransformer); $this->add($addresses); }