本文整理汇总了PHP中Symfony\Component\Form\FormFactoryInterface::createBuilder方法的典型用法代码示例。如果您正苦于以下问题:PHP FormFactoryInterface::createBuilder方法的具体用法?PHP FormFactoryInterface::createBuilder怎么用?PHP FormFactoryInterface::createBuilder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\FormFactoryInterface
的用法示例。
在下文中一共展示了FormFactoryInterface::createBuilder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getForm
public function getForm(ResourceInterface $resource)
{
$resourceClassName = \Doctrine\Common\Util\ClassUtils::getClass($resource);
$resourceParts = explode("\\", $resourceClassName);
$resourceParts[count($resourceParts) - 2] = 'Form';
$resourceParts[count($resourceParts) - 1] .= 'Type';
$formType = implode("\\", $resourceParts);
if (class_exists($formType)) {
return $this->formFactory->create(new $formType(), $resource);
}
$options = array('data_class' => $resourceClassName);
$builder = $this->formFactory->createBuilder('form', $resource, $options);
$reflectionClass = new \ReflectionClass($resourceClassName);
$annotationClass = 'uebb\\HateoasBundle\\Annotation\\FormField';
foreach ($reflectionClass->getProperties() as $propertyReflection) {
/**
* @var \uebb\HateoasBundle\Annotation\FormField $annotation
*/
$annotation = $this->annotationReader->getPropertyAnnotation($propertyReflection, $annotationClass);
if ($annotation) {
$builder->add($propertyReflection->getName(), $annotation->type, is_array($annotation->options) ? $annotation->options : array());
}
}
$form = $builder->getForm();
return $form;
}
示例2: create
/**
* {@inheritdoc}
*/
public function create($namespace, $data = null, array $options = [])
{
$schema = $this->schemaRegistry->getSchema($namespace);
$builder = $this->formFactory->createBuilder('form', $data, array_merge_recursive(['data_class' => null], $options));
$schema->buildForm($builder);
return $builder->getForm();
}
示例3: getFormBuilder
/**
* @return FormBuilderInterface
*/
protected function getFormBuilder()
{
if (!$this->formBuilder) {
$this->formBuilder = $this->formFactory->createBuilder($this->getFormType(), [], array_merge($this->getOr(FilterUtility::FORM_OPTIONS_KEY, []), ['csrf_protection' => false]));
}
return $this->formBuilder;
}
示例4: invoke
public function invoke(Request $request)
{
$type = new LoginFormType($request);
$builder = $this->formFactory->createBuilder($type, [], ['action' => $this->checkPath]);
$form = $builder->getForm();
return ['form' => $form->createView()];
}
示例5: contactAction
/**
* @Route("/contact", name="contact_route")
* @param Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function contactAction(Request $request)
{
/** @var AnonymousToken $token */
$token = $this->tokenStorage->getToken();
/** @var User $user */
$user = $token->getUser();
$contact = new Contact();
if ($user !== 'anon.') {
/** @var User $user */
$contact->setEmail($user->getEmail());
$contact->setUser($user);
}
$emailGetParam = $request->query->get('email');
if (!empty($emailGetParam)) {
$contact->setEmail($emailGetParam);
}
$form = $this->formFactory->createBuilder(FormType::class, $contact)->add('email', TextType::class, ['attr' => ['placeholder' => 'votre@adresse.email']])->add('message', TextareaType::class, ['attr' => ['maxlength' => 1000, 'rows' => 10]])->add('submit', SubmitType::class, ['label' => 'Envoyer'])->getForm();
$form->handleRequest($request);
if ($form->isValid()) {
$this->contactService->record($contact);
$this->session->getFlashBag()->add(static::FLASH_BAG_EMAIL, $contact->getEmail());
return new RedirectResponse($this->router->generate('confirmation_contact_route'));
} else {
return new Response($this->templating->render('base.html.twig', [TwigNodeTemplateTreeSection::TEMPLATE_TREE_BRANCH => 'contact', 'form' => $form->createView()]), $form->isSubmitted() ? Response::HTTP_BAD_REQUEST : Response::HTTP_OK);
}
}
示例6: create
/**
* {@inheritdoc}
*/
public function create($namespace)
{
$schema = $this->schemaRegistry->getSchema($namespace);
$builder = $this->formFactory->createBuilder('form', null, array('data_class' => null));
$schema->buildForm($builder);
return $builder->getForm();
}
示例7: createForm
/**
* Gets the form
*
* @param \Sonata\AdminBundle\Util\AdminObjectAclData $data
* @return \Symfony\Component\Form\Form
*/
public function createForm(AdminObjectAclData $data)
{
// Retrieve object identity
$objectIdentity = ObjectIdentity::fromDomainObject($data->getObject());
$acl = $data->getSecurityHandler()->getObjectAcl($objectIdentity);
if (!$acl) {
$acl = $data->getSecurityHandler()->createAcl($objectIdentity);
}
$data->setAcl($acl);
$masks = $data->getMasks();
// Create a form to set ACL
$formBuilder = $this->formFactory->createBuilder('form');
foreach ($data->getAclUsers() as $aclUser) {
$securityIdentity = UserSecurityIdentity::fromAccount($aclUser);
foreach ($data->getUserPermissions() as $permission) {
try {
$checked = $acl->isGranted(array($masks[$permission]), array($securityIdentity));
} catch (NoAceFoundException $e) {
$checked = false;
}
$formBuilder->add($aclUser->getId() . $permission, 'checkbox', array('required' => false, 'data' => $checked));
}
}
$form = $formBuilder->getForm();
$data->setForm($form);
return $form;
}
示例8: build
public function build(GenericResourceElement $element)
{
$resources = $this->getResourceGroup($element->getKey());
$builder = $this->formFactory->createBuilder('form', $this->createFormData($element, $element->getRepository(), $resources), $element->getResourceFormOptions());
$this->buildForm($element, $builder, $resources);
return $builder->getForm();
}
示例9: create
/**
* {@inheritdoc}
*/
public function create($schemaAlias, $data = null, array $options = [])
{
/** @var SchemaInterface $schema */
$schema = $this->schemaRegistry->get($schemaAlias);
$builder = $this->formFactory->createBuilder('form', $data, array_merge_recursive(['data_class' => null], $options));
$schema->buildForm($builder);
return $builder->getForm();
}
示例10: createForm
/**
* Creates a form
*
* @param CategoryInterface $category
*
* @return Form
*/
public function createForm(CategoryInterface $category)
{
$topic = new $this->modelClass();
$topic->setCategory($category);
$topic->setUser($this->getAuthenticatedUser());
$builder = $this->formFactory->createBuilder($this->type, $topic);
return $builder->getForm();
}
示例11: createForm
/**
* Creates a form
*
* @param TopicInterface $topic
*
* @return Form
*/
public function createForm(TopicInterface $topic)
{
$post = new $this->modelClass();
$post->setTopic($topic);
$post->setUser($this->getAuthenticatedUser());
$builder = $this->formFactory->createBuilder($this->type, $post);
return $builder->getForm();
}
示例12: testLabelPrefix
public function testLabelPrefix()
{
$form = $this->factory->createBuilder(FormType::class, null, ['label_prefix' => $labelPrefix = 'prefix'])->add($buttonName = 'button', ButtonType::class)->getForm();
$view = $form->createView();
$buttonView = $view->children[$buttonName];
$this->assertArrayHasKey('label', $buttonView->vars);
$this->assertSame($labelPrefix . '.' . $buttonName, $buttonView->vars['label']);
}
示例13: createForm
/**
* {@inheritdoc}
*/
public function createForm(array $options)
{
$builder = $this->formFactory->createBuilder($this->type, $this->entity, $options);
if ($this->action !== null) {
$builder->setAction($this->action);
}
$this->form = $builder->getForm();
return $this->form;
}
示例14: buildForm
/**
* @return FormInterface
*/
public function buildForm()
{
$builder = $this->formFactory->createBuilder('form', null);
foreach ($this->tabs as $tab) {
$tab->buildForm($builder);
}
$this->form = $builder->getForm();
return $this->form;
}
示例15: buildForm
/**
* @return FormInterface
*/
public function buildForm()
{
$builder = $this->formFactory->createBuilder('form', null, array('cascade_validation' => true));
foreach ($this->tabs as $tab) {
$tab->buildForm($builder);
}
$this->form = $builder->getForm();
return $this->form;
}