作者:dongilber
项目:mauti
/**
* @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);
}
作者:norzechowic
项目:resource-repository-bundl
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);
}
作者:dongilber
项目:mauti
/**
* {@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);
}
作者:hd-dema
项目:Chewbacc
/**
* {@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;
}
}
}
作者:weeme
项目:hangman_lennar
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);
}
作者:polido
项目:symfony_sample_tod
/**
* @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()];
}
作者:rodolfobandeir
项目:cr
/**
* 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;
}
作者:flintlab
项目:formmetadatabundl
/**
* 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;
}
作者:daniel-iwanie
项目:ISI-PR
/**
* 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;
}
作者:ampisof
项目:user-bundl
/**
* @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);
}
作者:BigfishCM
项目:UserBundl
/**
* @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());
}
作者:xxspartan1
项目:BMS-Marke
/**
* @test
*/
public function shouldNotBindInvalidValue()
{
$form = $this->formFactory->create('payum_payment_factories_choice');
$form->submit('invalid');
$this->assertNull($form->getData());
}
作者:noglitchy
项目:pim-community-de
/**
* 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;
}
作者:Maksol
项目:platfor
/**
* @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());
}
作者:roomthirtee
项目:Room13WizardBundl
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;
}
作者:ffff591
项目:Blo
/**
* @Route("/")
* @Method("post")
*/
public function indexPostAction(Request $request)
{
$form = $this->form_factory->create('blog_article');
$form->handleRequest($request);
if ($form->isValid()) {
$this->service->add($form->getData());
return $this->redirect($this->generateUrl('app_admin_blogpost_complete'));
}
return $this->render('Admin/Blog/index.html.twig', ['form' => $form->createView()]);
}
作者:partiku
项目:DinnerTim
/**
* @ApiDoc(
* description="Create a new Object",
* formType="DinnerTime\UserInterface\RestBundle\Form\MenuCardType"
* )
* @param Request $request
* @param Restaurant $restaurant
*
* @return View
*/
public function postMenucardsAction(Request $request, Restaurant $restaurant)
{
$form = $this->formFactory->create(new MenuCardType(), new AddNewMenuCardToRestaurantCommand($restaurant));
$form->submit($request->request->all());
if ($form->isValid()) {
$this->useCase->handle($form->getData());
return View::create($form->getData(), Codes::HTTP_CREATED);
}
return View::create($form);
}
作者:haso
项目:paymentsuit
/**
* Builds form given success and fail urls
*
* @param $responseRoute
* @return FormBuilder
*/
public function buildForm($responseRoute)
{
$formBuilder = $this->formFactory->createNamedBuilder(null);
$orderId = $this->paymentBridge->getOrderId() . '#' . date('Ymdhis');
$fields = array('usuario' => $this->user, 'gran_total' => $this->paymentBridge->getAmount(), 'referencia' => $this->paymentBridge->getOrderDescription(), 'url_respuesta' => $responseRoute);
//echo $this->cps;die();
$formKey = $this->encryptor->encrypt(implode('', $fields));
$formBuilder->setAction($this->gateway)->setMethod('POST')->add('usuario', 'hidden', array('data' => $this->user))->add('gran_total', 'hidden', array('data' => $this->paymentBridge->getAmount()))->add('referencia_ext', 'hidden', array('data' => $this->paymentBridge->getOrderDescription()))->add('url_respuesta', 'hidden', array('data' => $responseRoute))->add('key', 'hidden', array('data' => $formKey))->add('order_id', 'hidden', array('data' => $orderId))->add('Submit', 'hidden', array('data' => 'Pagar'));
return $formBuilder;
}
作者:ffff591
项目:Blo
/**
* @Route("/", name="category_registration_save")
* @Method("post")
*/
public function saveAction(Request $request)
{
$form = $this->form_factory->create('category');
$form->handleRequest($request);
if ($form->isValid()) {
$this->service->add($form->getData());
return $this->redirect($this->generateUrl('app_admin_category_complete'));
}
return $this->render('Admin/Category/Registration/index.html.twig', ['form' => $form->createView()]);
}
作者:Charlie-Luca
项目:InfiniteFormBundl
public function testInvalidTest()
{
$twig = new \Twig_Environment(new \Twig_Loader_Array(array('template' => '{{ form is invalid ? 1 : 0 }}')));
$twig->addExtension(new FormExtension());
$formWithError = $this->formFactory->create('text');
$formWithError->addError(new FormError('test error'));
$this->assertEquals('1', $twig->render('template', array('form' => $formWithError->createView())));
$formWithoutError = $this->formFactory->create('text');
$this->assertEquals('0', $twig->render('template', array('form' => $formWithoutError->createView())));
}