本文整理汇总了PHP中Symfony\Component\Form\FormFactory::createBuilder方法的典型用法代码示例。如果您正苦于以下问题:PHP FormFactory::createBuilder方法的具体用法?PHP FormFactory::createBuilder怎么用?PHP FormFactory::createBuilder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\FormFactory
的用法示例。
在下文中一共展示了FormFactory::createBuilder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createFormBuilder
/**
* Obtains any form metadata from the entity and adds itself to the form
* @param $entity
* @param $form
* @return
*/
public function createFormBuilder($entity, $data = null, array $options = array())
{
// Build the $form
$formBuilder = $this->factory->createBuilder('form', $data, $options);
// Read the entity meta data and add to the form
if (empty($this->drivers)) {
return $formBuilder;
}
// Look to the readers to find metadata
foreach ($this->drivers as $driver) {
$metadata = $driver->getMetadata($entity);
if (!empty($metadata)) {
break;
}
}
if (empty($metadata)) {
return $formBuilder;
}
// Configure the form
$fields = $metadata->getFields();
foreach ($fields as $field) {
// TODO: Detect "new x()" in field value or type option for AbstractType creation
// TODO: Detect references to "%service.id%" for service constructor dependency
$formBuilder->add($field->name, $field->value, $field->options);
}
return $formBuilder;
}
示例2: createToggleAccessOption
/**
* Creates toggle access option.
*
* @return Form
*/
public function createToggleAccessOption()
{
/** @var FormBuilder $formBuilder */
$formBuilder = $this->formFactory->createBuilder('form');
$form = $formBuilder->add('submit', 'submit', ['attr' => ['class' => 'btn']])->getForm();
return $form;
}
示例3: buildForm
public function buildForm()
{
$def = $this->definitions[$this->getCurrentStep()];
$methodName = 'build' . implode('', array_map('ucfirst', explode('-', $this->getCurrentStep()))) . 'Form';
$builder = $this->formFactory->createBuilder('form', $this->getSubject(), array('validation_groups' => $def['validation_groups']));
$this->{$methodName}($builder);
$form = $builder->getForm();
return $form;
}
示例4: registerForm
public function registerForm(Request $request)
{
if ($this->pageStack->isLoggedIn()) {
return $this->templating->renderResponse('JarvesBundle:User:logout.html.twig');
}
$user = new User();
$form = $this->formFactory->createBuilder()->setData($user)->add('email', EmailType::class)->add('password', PasswordType::class)->add('save', SubmitType::class, array('label' => 'Register'))->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
}
return $this->templating->renderResponse('JarvesBundle:User:register.html.twig', ['form' => $form->createView()]);
}
示例5: createFormBuilder
/**
* Obtains any form metadata from the entity and adds itself to the form
* @param string $data
* @param array $options
* @return \Symfony\Component\Form\FormBuilderInterface
*/
public function createFormBuilder($data = null, array $options = array())
{
// Build the $form
$formBuilder = $this->factory->createBuilder('form', $data, $options);
// Read the entity meta data and add to the form
if (empty($this->drivers)) {
return $formBuilder;
}
// Look to the readers to find metadata
foreach ($this->drivers as $driver) {
$metadata = $driver->getMetadata($data);
if (!empty($metadata)) {
break;
}
}
if (empty($metadata)) {
return $formBuilder;
}
// Configure the form
$fields = $metadata->getFields();
foreach ($fields as $field) {
// TODO: Detect "new x()" in field value or type option for AbstractType creation
// TODO: Detect references to "%service.id%" for service constructor dependency
$formBuilder->add($field->name, $field->value, $field->options);
}
$groups = $metadata->getGroups();
foreach ($groups as $groupName => $fields) {
$builder = $formBuilder->create($groupName, 'form', array('virtual' => true));
foreach ($fields as $field) {
$builder->add($field->name, $field->value, $field->options);
}
$formBuilder->add($builder);
}
$entities = $metadata->getFieldEntities();
foreach ($entities as $entity) {
$fieldEntityType = new FieldEntityType($entity->getClass(), $entity->getName(), $entity->getFields());
$options = $entity->getOptions();
if ($entity->isList()) {
$formBuilder->add($entity->getName(), 'collection', array('type' => $fieldEntityType, 'allow_add' => true, 'allow_delete' => true, 'prototype' => true, 'options' => $entity->getOptions()));
} else {
$formBuilder->add($entity->getName(), $fieldEntityType, $options);
}
}
$formTypes = $metadata->getFormTypes();
foreach ($formTypes as $formType) {
$formTypeInstance = new $formType->value();
$formBuilder->add($formType->name, $formTypeInstance);
}
return $formBuilder;
}
示例6: getForm
public function getForm(Request $request, $inline = 0)
{
$_locale = $request->getSession()->get('sf_locale', $this->default_locale);
$locale = new Locale();
$locale->setLocale($_locale);
$locale->setRedirectUrl($request->getRequestUri());
if (!isset($this->languages[$_locale])) {
throw new \Exception(\sprintf('invalid langauge locale: `%s` , support langages: %s ', $_locale, join(', ', array_keys($this->languages))));
}
$languages = $this->languages;
if ('POST' === $request->getMethod() && $inline) {
$languages = array($_locale => $this->languages[$_locale]);
}
$form = $this->form_factory->createBuilder('form', $locale, array('csrf_protection' => false))->add('locale', 'choice', array('choices' => $languages, 'attr' => array('class' => 'input-sm'), 'horizontal_input_wrapper_class' => 'sf_locale_select'))->add('redirect_url', 'hidden')->getForm();
return $form;
}
示例7: generateForm
public function generateForm(Entity\Test $test)
{
$data = array();
$form = $this->formFactory->createBuilder();
/** @var Entity\Question $question */
// foreach ($test->getQuestions() as $question) {
// /** @var Entity\Answer $answer */
// $answers = [];
// foreach ($question->getAnswers() as $answer) {
//// $form->add($question->getId(), RadioType::class, ['label' => $answer->getAnswer()]);
// $answers[$answer->getId()] = $answer->getAnswer();
// }
// $form->add($question->getId(), '');
// }
$form->add('favorite_cities', CollectionType::class, array('entry_type' => ChoiceType::class, 'entry_options' => array('choices' => array('nashville' => 'Nashville', 'paris' => 'Paris', 'berlin' => 'Berlin', 'london' => 'London'))));
return $form->getForm();
}
示例8: addAction
public function addAction(Request $request)
{
$entry = new DiaborgEntry();
$oldtimestamp = $request->get('oldtimestamp', null);
if (null !== $oldtimestamp) {
$oldtime = new DateTime();
$oldtime->setTimestamp($oldtimestamp);
$entry->setTimestamp($oldtime);
}
$form = $this->formFactory->createBuilder('form', $entry)->add('value', 'integer', array('required' => false))->add('be', 'number', array('required' => false))->add('insulin', 'number', array('required' => false))->add('timestamp', 'datetime')->add('save', 'submit')->getForm();
$form->handleRequest($request);
if ($form->isValid()) {
$this->repository->addEntity($entry);
return new RedirectResponse($this->router->generate('add', array('oldtimestamp' => $entry->getTimestamp()->getTimestamp())));
}
$formView = $form->createView();
return new Response($this->templating->render('Diaborg3Bundle:Form:form3.html.twig', array('form' => $formView)));
}
示例9: createDeleteForm
protected function createDeleteForm($id)
{
return $this->formFactory->createBuilder('form', ['id' => $id])->add('id', 'hidden')->getForm();
}
示例10: buildForm
/**
* {@inheritdoc}
*/
public function buildForm($data = null, array $options = [], $type = null)
{
$formType = is_null($type) ? $this->formType() : $type;
$form = $this->formFactory->createBuilder($formType, $data, $options)->getForm();
return $form;
}
示例11: getForm
/**
* @param $entity
*
* @return FormInterface
*/
public function getForm($entity)
{
$form = $this->formFactory->createBuilder('form', $entity, ['csrf_protection' => false, 'dynamic_fields_disabled' => true])->getForm();
return $form;
}
示例12: createTrombiBlock
public function createTrombiBlock()
{
$trombiFrom = $this->formFactory->createBuilder()->add('fullName', 'text', array('required' => false))->add('studentId', 'hidden', array('required' => false))->add('phoneNumber', 'hidden', array('required' => false))->add('uvs', 'hidden', array('required' => false))->add('branch', 'hidden', array('required' => false))->add('niveau', 'hidden', array('required' => false))->add('personnalMail', 'hidden', array('required' => false))->getForm();
$block = ['template' => 'EtuCoreBundle:Main/index_blocks:trombi.html.twig', 'context' => ['trombiForm' => $trombiFrom->createView()]];
return $block;
}
示例13: createForm
/**
* @param mixed $data
* @param array|null $options
*
* @return Form
*/
protected function createForm($data = null, array $options = null)
{
return $this->formFactory->createBuilder($this->formType, $data, is_array($options) ? $options : $this->defaultFormOptions)->getForm();
}
示例14: createFormBuilder
/**
* @param Module $module
* @param array $options
*
* @return \Symfony\Component\Form\FormBuilderInterface
*/
public function createFormBuilder(Module $module, array $options = array(), $formOptions = array(), FormBuilderInterface $parentForm = null)
{
$modules = $this->objectManager->getRepository('BigfishEavBundle:Module')->getFields($module->getId());
$formOptions = array_merge_recursive($formOptions, array('cascade_validation' => true, 'error_bubbling' => true, 'required' => true));
// build new form
/** @var $formBuilder \Symfony\Component\Form\FormBuilder **/
$formBuilder = $parentForm ? $parentForm : $this->formFactory->createBuilder('form', null, $formOptions);
$prepareBuilder = array();
$sortedFields = array();
foreach ($modules as $module) {
foreach ($module->getField() as $field) {
$formData = $this->fieldChain->getField($field, $module, $options);
if ($formData) {
$contstraints = $this->constraintChain->getConstraints($field->getConstraints());
$required = false;
foreach ($contstraints as $constraint) {
if ($constraint instanceof NotBlank) {
$required = true;
}
}
$formData['formAttributes']['constraints'] = $contstraints;
$formData['formAttributes']['required'] = $required;
$sortedFields[] = $formData['identifier'];
$formBuilder->add($formData['identifier'], $formData['formType'], $formData['formAttributes']);
}
}
}
foreach ($formBuilder->all() as $builder) {
$type = $builder->getType()->getName();
if ($type == 'fieldset') {
// var_dump($builder->getType());
$options = $builder->getOptions();
$aChildFields = $options['childFields'];
// remove unused childs and maintain order
$newFields = array_filter($sortedFields, function ($key) use($aChildFields) {
return in_array($key, $aChildFields);
});
$subForm = array();
foreach ($newFields as $childField) {
if ($formBuilder->has($childField)) {
if (($key = array_search($childField, $sortedFields)) !== false) {
unset($sortedFields[$key]);
}
// echo "<hr>";
// var_dump($formBuilder->get($childField)->getName());
// var_dump($formBuilder->get($childField)->getRequired());
// echo "</hr>";
$field = $formBuilder->get($childField);
$subForm[] = $field;
$formBuilder->remove($childField);
}
}
$elem = $formBuilder->get($builder->getName());
$formBuilder->remove($builder->getName());
$formBuilder->add($elem->getName(), $type, array('subforms' => $subForm, 'label' => false, 'required' => false, 'mapped' => false, 'title' => $elem->getOption('title'), 'description' => $elem->getOption('description'), 'fieldsetId' => $elem->getOption('fieldsetId')));
}
}
$this->reorder($formBuilder, $sortedFields);
// rebuild form
foreach ($formBuilder->all() as $element) {
if ($formBuilder->has($element->getName())) {
$holdElement = $formBuilder->get($element->getName());
$formBuilder->remove($element->getName());
$formBuilder->add($holdElement);
foreach ($holdElement->all() as $child) {
if ($element->has($child->getName())) {
$formBuilder->add($element->get($child->getName()));
$element->remove($child->getName());
}
}
}
}
return $formBuilder;
}
示例15: buildFormFromType
/**
* Build the form object to return to the templating engine
*
* @param Type $type
* @param array $options
*
* @return FormView
*/
public function buildFormFromType(Type $type, array $options = array())
{
return $this->formFactory->createBuilder($type, null, $options)->getForm()->createView();
}