本文整理汇总了PHP中Symfony\Component\Form\FormFactory类的典型用法代码示例。如果您正苦于以下问题:PHP FormFactory类的具体用法?PHP FormFactory怎么用?PHP FormFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FormFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createForm
/**
* @param object $entity
* @param \Symfony\Component\Form\FormFactory $formFactory
* @param null $action
* @param array $options
*
* @return \Symfony\Component\Form\FormInterface
*/
public function createForm($entity, $formFactory, $action = null, $options = [])
{
$fields = $this->leadFieldModel->getFieldListWithProperties();
$choices = [];
foreach ($fields as $alias => $field) {
if (!isset($choices[$field['group_label']])) {
$choices[$field['group_label']] = [];
}
$choices[$field['group_label']][$alias] = $field['label'];
}
// Only show the lead fields not already used
$usedLeadFields = $this->session->get('mautic.form.' . $entity['formId'] . '.fields.leadfields', []);
$testLeadFields = array_flip($usedLeadFields);
$currentLeadField = isset($entity['leadField']) ? $entity['leadField'] : null;
if (!empty($currentLeadField) && isset($testLeadFields[$currentLeadField])) {
unset($testLeadFields[$currentLeadField]);
}
foreach ($choices as &$group) {
$group = array_diff_key($group, $testLeadFields);
}
$options['leadFields'] = $choices;
$options['leadFieldProperties'] = $fields;
if ($action) {
$options['action'] = $action;
}
return $formFactory->create('formfield', $entity, $options);
}
示例2: array
function it_returns_form_builder_with_additional_file_options_and_file_constraints(FormFactory $factory, FormBuilder $form, NotBlank $constraint)
{
$this->addConstraint($constraint);
$this->setFormOptions(array('file_type' => 'fsi_image', 'file_options' => array('file_option' => 'value')));
$factory->createNamedBuilder('fileValue', 'fsi_removable_file', null, array('label' => false, 'required' => false, 'file_type' => 'fsi_image', 'file_options' => array('file_option' => 'value', 'constraints' => array($constraint))))->shouldBeCalled()->willReturn($form);
$this->getFormBuilder($factory)->shouldReturn($form);
}
示例3: createForm
/**
* {@inheritdoc}
*
* @param object $entity
* @param \Symfony\Component\Form\FormFactory $formFactory
* @param null $action
* @param array $options
*
* @throws NotFoundHttpException
*/
public function createForm($entity, $formFactory, $action = null, $options = [])
{
if (!$entity instanceof Focus) {
throw new MethodNotAllowedHttpException(['Focus']);
}
if (!empty($action)) {
$options['action'] = $action;
}
return $formFactory->create('focus', $entity, $options);
}
示例4: resolveItemToAdd
/**
* {@inheritdoc}
*/
public function resolveItemToAdd(Request $request)
{
/*
* We're getting here product set id via query but you can easily override route
* pattern and use attributes, which are available through request object.
*/
if ($id = $request->query->get('id')) {
if ($product_set = $this->productSetManager->findSet($id)) {
/*
* To have it flexible, we allow adding single item by GET request
* and also user can provide desired quantity by form via POST request.
*/
$item = $this->itemManager->createItem();
$item->setProductSet($product_set);
if ('POST' === $request->getMethod()) {
$form = $this->formFactory->create('chewbacca_cart_item');
$form->setData($item);
$form->bindRequest($request);
if (!$form->isValid()) {
return false;
}
}
return $item;
}
}
}
示例5: postGameAction
public function postGameAction(Request $request)
{
$uuid = $this->uuidGenerator->generate();
$gameStartCommand = new GameStartCommand($uuid, "hup");
$form = $this->formFactory->create(new GameStartType(), $gameStartCommand);
$this->handleForm($request, $form, $uuid, $gameStartCommand);
}
示例6: boxAction
/**
* @Template(":Todo/Search:box.html.twig")
* @return array
*/
public function boxAction(Request $request)
{
$search = new TodoList();
$form = $this->formFactory->create('todo_list', $search);
$form->handleRequest($request);
return ['form' => $form->createView()];
}
示例7: process
/**
* Process form
*
* @param Call $entity
*
* @return bool True on successful processing, false otherwise
*/
public function process(Call $entity)
{
$targetEntityClass = $this->request->get('entityClass');
$targetEntityId = $this->request->get('entityId');
$options = [];
if ($targetEntityClass && $this->request->getMethod() === 'GET') {
$targetEntity = $this->entityRoutingHelper->getEntity($targetEntityClass, $targetEntityId);
if (!$entity->getId()) {
$entity->setPhoneNumber($this->phoneProvider->getPhoneNumber($targetEntity));
}
$options = ['phone_suggestions' => array_unique(array_map(function ($item) {
return $item[0];
}, $this->phoneProvider->getPhoneNumbers($targetEntity)))];
}
$this->form = $this->formFactory->createNamed($this->formName, $this->formType, $entity, $options);
$this->form->setData($entity);
if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
$this->form->submit($this->request);
if ($this->form->isValid()) {
if ($targetEntityClass) {
$targetEntity = $this->entityRoutingHelper->getEntity($targetEntityClass, $targetEntityId);
$this->callActivityManager->addAssociation($entity, $targetEntity);
$phones = $this->phoneProvider->getPhoneNumbers($targetEntity);
foreach ($phones as $phone) {
if ($entity->getPhoneNumber() === $phone[0]) {
$this->callActivityManager->addAssociation($entity, $phone[1]);
}
}
}
$this->onSuccess($entity);
return true;
}
}
return false;
}
示例8: 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;
}
示例9: 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;
}
示例10: getLoginForm
/**
* @param null $data
* @param array $options
* @return \Symfony\Component\Form\Form
*/
public function getLoginForm($data = null, array $options = [])
{
$options['last_username'] = $this->authenticationUtils->getLastUsername();
if (!array_key_exists('action', $options)) {
$options['action'] = $this->router->generate('security_login_check');
}
return $this->formFactory->create(LoginType::class, $data, $options);
}
示例11: createAction
/**
* @Route("/users/new", name="user_new")
* @Template("BigfishUserBundle:Default:form.html.twig")
*/
public function createAction(Request $request)
{
$user = $this->_security->getToken()->getUser();
$entity = $this->_userManager->createUser();
$form = $this->_formFactory->create(new UserType(), $entity);
// $this->_formFactory->create(, $data, $options);
return array('form' => $form->createView());
}
示例12: shouldNotBindInvalidValue
/**
* @test
*/
public function shouldNotBindInvalidValue()
{
$form = $this->formFactory->create('payum_payment_factories_choice');
$form->submit('invalid');
$this->assertNull($form->getData());
}
示例13: createForm
/**
* Create form for role manipulation
*
* @param Role $role
* @return FormInterface
*/
public function createForm(Role $role)
{
foreach ($this->privilegeConfig as $configName => $config) {
$this->privilegeConfig[$configName]['permissions'] = $this->aclManager->getPrivilegeRepository()->getPermissionNames($config['types']);
}
$this->form = $this->formFactory->create(new ACLRoleType($this->privilegeConfig), $role);
return $this->form;
}
示例14: testLayout
/**
* @dataProvider layoutProvider
*/
public function testLayout($formOptions, $formItems, $expectedBlocks)
{
$formBuilder = $this->factory->createNamedBuilder('test', 'form', null, $formOptions);
$this->buildForm($formBuilder, $formItems);
$formView = $formBuilder->getForm()->createView();
$result = $this->builder->build($formView);
$expected = $this->getBlocks($expectedBlocks);
$this->assertEquals($expected, $result->toArray());
}
示例15: 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;
}