本文整理匯總了PHP中Symfony\Component\Form\FormBuilderInterface::getFormFactory方法的典型用法代碼示例。如果您正苦於以下問題:PHP FormBuilderInterface::getFormFactory方法的具體用法?PHP FormBuilderInterface::getFormFactory怎麽用?PHP FormBuilderInterface::getFormFactory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\Form\FormBuilderInterface
的用法示例。
在下文中一共展示了FormBuilderInterface::getFormFactory方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->addEventSubscriber(new AddCodeFormSubscriber())->addEventSubscriber(new BuildReportDataFetcherFormSubscriber($this->dataFetcherRegistry, $builder->getFormFactory()))->addEventSubscriber(new BuildReportRendererFormSubscriber($this->rendererRegistry, $builder->getFormFactory()))->add('name', 'text', ['label' => 'sylius.form.report.name', 'required' => true])->add('description', 'textarea', ['label' => 'sylius.form.report.description', 'required' => false])->add('dataFetcher', 'sylius_data_fetcher_choice', ['label' => 'sylius.form.report.data_fetcher'])->add('renderer', 'sylius_renderer_choice', ['label' => 'sylius.form.report.renderer.label']);
$prototypes = ['renderers' => [], 'dataFetchers' => []];
foreach ($this->rendererRegistry->all() as $type => $renderer) {
$formType = sprintf('sylius_renderer_%s', $renderer->getType());
if (!$formType) {
continue;
}
try {
$prototypes['renderers'][$type] = $builder->create('rendererConfiguration', $formType)->getForm();
} catch (\InvalidArgumentException $e) {
continue;
}
}
foreach ($this->dataFetcherRegistry->all() as $type => $dataFetcher) {
$formType = sprintf('sylius_data_fetcher_%s', $dataFetcher->getType());
if (!$formType) {
continue;
}
try {
$prototypes['dataFetchers'][$type] = $builder->create('dataFetcherConfiguration', $formType)->getForm();
} catch (\InvalidArgumentException $e) {
continue;
}
}
$builder->setAttribute('prototypes', $prototypes);
}
示例2: buildForm
/**
* {@inheritDoc}
*/
public function buildForm(FormBuilderInterface $formBuilder, array $options)
{
$subscriber = new AddIdFieldSubscriber($formBuilder->getFormFactory());
$formBuilder->addEventSubscriber($subscriber);
$subscriber = new AddContentTypeFieldSubscriber($formBuilder->getFormFactory(), $this->mediasizes);
$formBuilder->addEventSubscriber($subscriber);
$contentTypeChoices = $this->contentTypes;
reset($contentTypeChoices);
$prefContentTypeChoice = key($contentTypeChoices);
$sizeclassChoices = $this->contentsizes;
reset($sizeclassChoices);
$prefSizeclassChoice = key($sizeclassChoices);
$formBuilder->add('title', 'text', array('label' => 'Content Block Title', 'required' => true))->add('publishedState', 'choice', array('choices' => array('0' => 'Unpublished', '1' => 'Published'), 'preferred_choices' => array('1'), 'label' => 'Publish State', 'required' => true))->add('availability', 'choice', array('choices' => array('page' => 'Page Only', 'global' => 'Global'), 'preferred_choices' => array('0'), 'label' => 'Available to', 'required' => true))->add('showTitle', 'choice', array('choices' => array('0' => 'Hide Title', '1' => 'Show Title'), 'preferred_choices' => array('1'), 'label' => 'Title Display State', 'required' => true))->add('ordering', 'hidden', array('attr' => array('class' => 'orderField'), 'label' => 'Content Block Ordering', 'required' => true))->add('className', 'text', array('label' => 'CSS Class', 'required' => false))->add('idName', 'text', array('label' => 'CSS Id', 'required' => false))->add('sizeClass', 'choice', array('choices' => $sizeclassChoices, 'preferred_choices' => array($prefContentTypeChoice), 'label' => 'Content Block Width', 'required' => true))->add('contentType', 'choice', array('choices' => $contentTypeChoices, 'preferred_choices' => array($prefSizeclassChoice), 'label' => 'Content Type', 'required' => true));
}
示例3: buildForm
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$customerId = $options['customerId'];
$builder->add('name')->add('code')->add('file', 'file', array("required" => false))->add('sucursales', 'entity', array('class' => 'BackendCustomerAdminBundle:Sucursal', 'query_builder' => function (EntityRepository $er) use($customerId) {
return $er->createQueryBuilder('u')->where('u.customer = ' . $customerId)->orderBy('u.name', 'ASC');
}, 'multiple' => true, 'mapped' => true, 'required' => true))->add('precio')->add('alwaysAvailable')->add('maxVariedad')->add('minVariedad')->add('qtyVariedad', 'checkbox', array('value' => 1, 'required' => false))->add('isActive', 'checkbox', array('value' => 1, 'required' => false))->add('file', 'file', array("required" => false))->add('description');
//deben ser las variedades del producto que ya esten cargadas previamente para el mismo customer
$builder->add('variedades', 'entity', array('class' => 'BackendCustomerAdminBundle:Variedad', 'query_builder' => function (EntityRepository $er) use($customerId) {
return $er->createQueryBuilder('u')->where('u.customer = ' . $customerId)->orderBy('u.name', 'ASC');
}, 'multiple' => true, 'mapped' => true, 'required' => true));
$categoriaSubscriber = new CategoriaSubscriber($builder->getFormFactory());
$builder->addEventSubscriber($categoriaSubscriber);
$subcategoriaSubscriber = new SubcategoriaSubscriber($builder->getFormFactory());
$builder->addEventSubscriber($subcategoriaSubscriber);
}
示例4: buildForm
/**
* Adds a CSRF field to the form when the CSRF protection is enabled.
*
* @param FormBuilderInterface $builder The form builder
* @param array $options The options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
if (!$options['csrf_protection']) {
return;
}
$builder->setAttribute('csrf_factory', $builder->getFormFactory())->addEventSubscriber(new CsrfValidationListener($options['csrf_field_name'], $options['csrf_provider'], $options['intention'], $options['csrf_message'], $this->translator, $this->translationDomain));
}
示例5: buildForm
public function buildForm(FormBuilderInterface $builder, array $options)
{
$subscriber = new ReplaceNotSubmittedValuesByDefaultsListener($builder->getFormFactory());
$builder->addEventSubscriber($subscriber);
$builder->add('page', 'hidden', array('required' => false, 'attr' => array('id' => 'page')));
$builder->add('limit', 'hidden', array('required' => false, 'attr' => array('id' => 'limit')));
}
示例6: buildForm
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
// ajout de action si défini
if (isset($this->parametres['form_action'])) {
$builder->setAction($this->parametres['form_action']);
}
// Builder…
$factory = $builder->getFormFactory();
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use($factory) {
$data = $event->getData();
// important : GARDER CETTE CONDITION CI-DESSOUS (toujours !!!)
if (null === $data) {
return;
}
if (null === $data->getId()) {
// création
$event->getForm()->add('nom', 'textarea', array('label' => 'form.nom', 'required' => true, 'attr' => array('rows' => 6, 'style' => 'resize: vertical;')));
} else {
// L'entité existe : édition
$event->getForm()->add('nom', 'text', array('label' => 'form.nom', 'required' => true));
}
});
// ajoute les valeurs hidden, passés en paramètre
$builder = $this->addHiddenValues($builder);
// AJOUT SUBMIT
$builder->add('submit', 'submit', array('label' => 'form.enregistrer', 'attr' => array('class' => "btn btn-md btn-block btn-info")));
}
示例7: buildForm
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('date', 'date')->add('titre', 'text')->add('auteur', 'text')->add('contenu', 'textarea')->add('image', new ImageType())->add('categories', 'collection', array('type' => new CategorieType(), 'allow_add' => true, 'allow_delete' => true))->add('categories', 'entity', array('class' => 'SdzBlogBundle:Categorie', 'property' => 'nom', 'multiple' => true, 'expanded' => false));
$factory = $builder->getFormFactory();
// on ajoute une fonction qui permet d'écouter l'evenement
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use($factory) {
// on définit une fct qui seras exécuté lors de l'evenement
$article = $event->getData();
//dump($article);de;
$publi = $article->getPublication();
if (null === $article) {
return;
// on sort de la fonction lorque $article vaut null
}
//si l'article n'est pas encore publié c est adire que $publi=== null ou égale false c est adire
// n'a pas encoré été coché, on
// ajoute le champ de
// publication
if ($publi === null || $publi === false) {
$event->getForm()->add($factory->createNamed('publication', 'checkbox', null, array('required' => false, 'auto_initialize' => false)));
} else {
// sinon on le supprime
$event->getForm()->remove('publication');
}
});
}
示例8: buildForm
public function buildForm(FormBuilderInterface $builder, array $options)
{
// You could tag the permission managers and then get them
// here instead of hard coding ...
$builder->add('permissionType', 'choice', array('choices' => array('admin' => 'sonata admins', 'object' => 'objects', 'route' => 'routes'), 'label' => 'Permission Type'));
$builder->add('identity', 'tsk_identity_dropdown');
$builder->add('identityType', 'hidden');
$factory = $builder->getFormFactory();
// We use a closure to populate permissions and masks for user
$refreshPerms = function ($form, $perms) use($factory) {
$form->add($factory->createNamed('permissions', 'collection', $perms, array('type' => 'tsk_permission_type', 'options' => array('label_attr' => array('class' => 'perm-collection')))));
};
//
// Use FormEvents to add the permissions array dynamically
//
$builder->addEventListener(FormEvents::PRE_BIND, function (FormEvent $event) use($factory, $refreshPerms) {
$form = $event->getForm();
$data = $event->getData();
if (!empty($data['identity'])) {
$perms = $this->permissionsManager->getPermissionsForIdentity($data['identity'], $data['identityType']);
$refreshPerms($form, $perms);
}
});
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use($factory, $refreshPerms) {
$form = $event->getForm();
$data = $event->getData();
if ($data->getIdentity()) {
$perms = $this->permissionsManager->getPermissionsForIdentity($data->getIdentity(), $data->getIdentityType());
$refreshPerms($form, $perms);
}
});
}
示例9: buildForm
/**
* {@inheritDoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$tokenStorage = $options['token_storage'];
$builder->add('dni')->add('address')->add('city')->add('state', EntityType::class, array('class' => 'CoreBundle:State', 'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('c');
}, 'required' => false, 'placeholder' => 'Selecciona tu provincia'))->add('country', EntityType::class, array('class' => 'CoreBundle:Country', 'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('c');
}, 'required' => false, 'placeholder' => 'Selecciona tu país'))->add('postalCode')->add('phone')->add('phone2')->add('preferredSchedule', ChoiceType::class, array('choices' => Address::getSchedules(), 'required' => false, 'choices_as_values' => true));
$user = $tokenStorage->getToken()->getUser();
if (!$user) {
throw new \LogicException('The AddressFormType cannot be used without an authenticated user!');
}
$factory = $builder->getFormFactory();
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use($user, $factory) {
$form = $event->getForm();
// if user is a business, add the contact person field
// if ($user::BUSINESS == $user->getAccountType()) {
// $formOptions = array(
// 'required' => false
// );
//
// $form->add($factory->createNamed('contactPerson', 'text', null, $formOptions));
// }
});
}
示例10: buildForm
/**
* {@inheritDoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$conversation = $this->conversationContext->getConversation();
if ($conversation !== null) {
$builder->setAttribute('conversation_factory', $builder->getFormFactory());
}
}
示例11: buildForm
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('venue', 'text', ['label' => 'admin.registration_event.field.venue'])->add('address', 'text', ['label' => 'admin.registration_event.field.address'])->add('country', 'entity', ['label' => 'admin.registration_event.field.country', 'class' => 'AppBundle\\Entity\\Country', 'property' => 'name', 'required' => true, 'empty_value' => 'admin.form.select_empty_value', 'query_builder' => function ($repository) {
return $repository->createQueryBuilder('c')->add('orderBy', 's.name ASC');
}])->add('postalCode', 'text', ['label' => 'admin.registration_event.field.postal_code'])->add('date', 'date', ['label' => 'admin.registration_event.field.date', 'widget' => 'single_text'])->add('domain', 'choice', ['label' => 'admin.registration_event.field.domain', 'choices' => $this->domains])->add('time_groups', 'collection', ['label' => 'admin.registration_event.field.time_groups', 'type' => 'admin_time_group', 'allow_add' => true, 'allow_delete' => true, 'by_reference' => false]);
$factory = $builder->getFormFactory();
$refreshStates = function ($form, $country) use($factory) {
$stateAttr = $country ? [] : ['disabled' => 'disabled'];
$form->add($factory->createNamed('state', 'entity', null, ['label' => 'admin.registration_event.field.state', 'class' => 'AppBundle\\Entity\\State', 'property' => 'name', 'required' => true, 'empty_value' => 'admin.form.select_empty_value', 'auto_initialize' => false, 'attr' => $stateAttr, 'query_builder' => function (StateRepository $repository) use($country) {
return $repository->createQueryBuilder('s')->add('orderBy', 's.name ASC')->add('where', 's.country = :country')->setParameter('country', $country);
}]));
};
$refreshCities = function ($form, $state) use($factory) {
$cityAttr = $state ? [] : ['disabled' => 'disabled'];
$form->add($factory->createNamed('city', 'entity', null, ['label' => 'admin.registration_event.field.city', 'class' => 'AppBundle\\Entity\\City', 'property' => 'name', 'required' => true, 'empty_value' => 'admin.form.select_empty_value', 'auto_initialize' => false, 'attr' => $cityAttr, 'query_builder' => function (CityRepository $repository) use($state) {
return $repository->createQueryBuilder('cT')->add('orderBy', 'cT.name ASC')->add('where', 'cT.state = :state')->setParameter('state', $state);
}]));
};
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use($refreshStates, $refreshCities) {
$form = $event->getForm();
$data = $event->getData();
if ($data instanceof RegistrationEvent) {
$refreshStates($form, $data->getId() ? $data->getCountry() : null);
$refreshCities($form, $data->getId() ? $data->getState() : null);
}
});
$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use($refreshStates, $refreshCities) {
$form = $event->getForm();
$data = $event->getData();
$refreshStates($form, array_key_exists('country', $data) ? $data['country'] : null);
$refreshCities($form, array_key_exists('state', $data) ? $data['state'] : null);
});
}
示例12: buildForm
public function buildForm(FormBuilderInterface $builder, array $options)
{
if (!$options['honeypot']) {
return;
}
$builder->setAttribute('honeypot_factory', $builder->getFormFactory())->addEventSubscriber(new HoneypotValidationListener($this->translator, $this->translationDomain, $options['honeypot_field'], $options['honeypot_message']));
}
示例13: buildForm
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('type', 'choice', array('choices' => Beneficiary::getTypeChoices()))->add('first_name', 'text', array('required' => true))->add('middle_name', 'text', array('required' => false))->add('last_name', 'text', array('required' => true))->add('birth_date', 'date', array('widget' => 'single_text', 'format' => 'MM-dd-yyyy', 'attr' => array('class' => 'jq-date input-small')))->add('city', 'text', array('required' => true))->add('street', 'text', array('required' => true))->add('state', 'entity', array('class' => 'WealthbotAdminBundle:State', 'label' => 'State', 'empty_value' => 'Select a State'))->add('zip', 'text', array('required' => true))->add('relationship', 'text', array('required' => true))->add('share', 'number', array('required' => true));
$factory = $builder->getFormFactory();
$showSsn = $this->showSsn;
$updateSsn = function (FormInterface $form, $ssn) use($factory) {
$form->add($factory->createNamed('ssn_1', 'text', null, array('property_path' => false, 'attr' => array('value' => $ssn[1]), 'constraints' => array(new NotBlank(array('message' => 'Can not be blank.')), new Regex(array('pattern' => '/^\\d+$/', 'message' => 'Must be number.')), new Length(array('min' => 3, 'max' => 3, 'minMessage' => 'Must have {{ limit }} digits.', 'maxMessage' => 'Must have {{ limit }} digits.'))))))->add($factory->createNamed('ssn_2', 'text', null, array('property_path' => false, 'attr' => array('value' => $ssn[2]), 'constraints' => array(new NotBlank(array('message' => 'Can not be blank.')), new Regex(array('pattern' => '/^\\d+$/', 'message' => 'Must be number.')), new Length(array('min' => 2, 'max' => 2, 'minMessage' => 'Must have {{ limit }} digits.', 'maxMessage' => 'Must have {{ limit }} digits.'))))))->add($factory->createNamed('ssn_3', 'text', null, array('property_path' => false, 'attr' => array('value' => $ssn[3]), 'constraints' => array(new NotBlank(array('message' => 'Can not be blank.')), new Regex(array('pattern' => '/^\\d+$/', 'message' => 'Must be number.')), new Length(array('min' => 4, 'max' => 4, 'minMessage' => 'Must have {{ limit }} digits.', 'maxMessage' => 'Must have {{ limit }} digits.'))))));
};
$builder->addEventListener(FormEvents::PRE_BIND, function (FormEvent $event) use($updateSsn) {
$form = $event->getForm();
$data = $event->getData();
if (array_key_exists('ssn_1', $data) && array_key_exists('ssn_2', $data) && array_key_exists('ssn_3', $data)) {
$updateSsn($form, array('', $data['ssn_1'], $data['ssn_2'], $data['ssn_3']));
}
});
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use($updateSsn, $showSsn) {
$form = $event->getForm();
$data = $event->getData();
$ssn = array('', '', '', '');
if (true === $showSsn) {
if ($data !== null && preg_match('/^([0-9]{3})([0-9]{2})([0-9]{4})$/', $data->getSsn(), $matches)) {
$ssn = $matches;
}
}
$updateSsn($form, $ssn);
});
$builder->addEventListener(FormEvents::BIND, array($this, 'validatePreSave'));
if (!$this->isPreSaved) {
$builder->addEventListener(FormEvents::BIND, array($this, 'validate'));
}
}
示例14:
function it_builds_form_with_proper_fields(FormBuilderInterface $builder, FormFactoryInterface $factory)
{
$builder->getFormFactory()->willReturn($factory);
$builder->add('file', 'file', Argument::any())->shouldBeCalled()->willReturn($builder);
$builder->add('code', 'text', Argument::any())->shouldBeCalled()->willReturn($builder);
$this->buildForm($builder, []);
}
示例15: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('presentation', 'text', array('required' => false, 'label' => 'sylius.form.variant.presentation'));
if (!$options['master']) {
$builder->addEventSubscriber(new BuildVariantFormListener($this->variableName, $builder->getFormFactory()));
}
}