create() public method

public create ( $type = 'form', $data = null, array $options = [], Symfony\Component\Form\FormBuilderInterface $parent = null )
$options array
$parent Symfony\Component\Form\FormBuilderInterface
Beispiel #1
0
 /**
  * {@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;
         }
     }
 }
 /**
  * @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()];
 }
 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);
 }
Beispiel #4
0
 /**
  * @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);
 }
 /**
  * @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());
 }
 /**
  * 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;
 }
    /**
     * @test
     */
    public function shouldNotBindInvalidValue()
    {
        $form = $this->formFactory->create('payum_payment_factories_choice');

        $form->submit('invalid');

        $this->assertNull($form->getData());
    }
 /**
  * @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);
 }
 /**
  * @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()]);
 }
 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())));
 }
Beispiel #11
0
 /**
  * @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()]);
 }
 /**
  * @Route("/{id}", name="category_edit_post")
  * @ParamConverter("category", class="AppBundle:Category")
  * @Method("post")
  */
 public function editPostAction(Request $request, Category $category)
 {
     $form = $this->form_factory->create('category', $category);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $this->service->update();
         return $this->redirect($this->generateUrl('admin_category'));
     }
     return $this->render('Admin/Category/Registration/index.html.twig', ['form' => $form->createView()]);
 }
Beispiel #13
0
 /**
  * @Route("comment/{id}")
  * @ParamConverter("blog", class="AppBundle:BlogArticle")
  * @Method("post")
  */
 public function createAction(Request $request, BlogArticle $blog)
 {
     $comment = new Comment($blog);
     $form = $this->form_factory->create('comment', $comment);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $this->service->add($comment);
         return $this->redirect($this->generateUrl('app_blog_show', ['id' => $blog->getId()]));
     }
     return $this->render('Comment/form.html.twig', ['form' => $form->createView(), 'comment' => $comment]);
 }
 /**
  * @Route()
  * @Method("POST")
  *
  * @param Request $request
  * @return RedirectResponse
  */
 public function saveAction(Request $request)
 {
     $form = $this->formFactory->create('todo');
     $form->handleRequest($request);
     if ($form->isValid()) {
         $this->addTodo->run($form->getData());
         $this->notification->info('タスクを登録しました');
     } else {
         $this->notification->danger('タスクの登録に失敗しました');
     }
     return new RedirectResponse($this->router->generate('app_todo_default_index'));
 }
 /**
  * @Route("/newsletter/new", name="newsletter_new")
  *
  * @return Response
  *
  * @throws \Exception
  * @throws \Twig_Error
  */
 public function newAction(Request $request)
 {
     $resolvedForm = $this->formFactory->create(new NewsletterCampaignFormType());
     if ($request->isMethod("POST")) {
         $resolvedForm->handleRequest($request);
         if ($resolvedForm->isValid()) {
             $newsletterCampaign = $resolvedForm->getData();
             $this->newsletterCampaignManager->save($newsletterCampaign);
             $this->session->getFlashBag()->add('message', 'Saved!');
         }
     }
     return new Response($this->twig->render('AppBundle:Newsletter:new.html.twig', array('form' => $resolvedForm->createView(), '')));
 }
 /**
  * @param Request $request
  * @param $user
  * @return bool|Form|FormInterface
  */
 public function Admineditprofile(Request $request, $user)
 {
     $form = $this->FormFactory->create('form_admin', $user);
     if ($request->getMethod() === 'POST') {
         $form->get('roles')->submit($this->roles());
         if ($form->isValid()) {
             $user = $form->getData();
             $em = $this->doctrine->getManager();
             $em->persist($user);
             $em->flush();
             return true;
         }
     }
     return $form;
 }
 /**
  * @Template()
  * @param Request $request
  * @return array|RedirectResponse
  */
 public function addAction(Request $request)
 {
     $row = new InvoiceRow();
     $form = $this->formFactory->create('invoicity_row_form', $row);
     if ($request->isMethod('post')) {
         $form->submit($request);
         if ($form->isValid()) {
             $row->setUser($this->getCurrentUser());
             $this->entityManager->persist($row);
             $this->entityManager->flush();
             return new RedirectResponse($this->router->generate('invoicity_row_overview'));
         }
     }
     return array('form' => $form->createView());
 }
 /**
  * @param Request $request
  * @param $user
  * @return bool|Form|FormInterface
  */
 public function UserEditProfile(Request $request, $user)
 {
     $form = $this->FormFactory->create('profile_edit', $user);
     if ($request->getMethod() === 'POST') {
         $form->handleRequest();
         if ($form->isValid()) {
             $user = $form->getData();
             $em = $this->doctrine->getEntityManager();
             $em->persist($user);
             $em->flush();
             return true;
         }
     }
     return $form;
 }
 /**
  * @param Request $request
  * @param string $formClass
  * @param string $entityClass
  * @return array
  */
 public function processForm(Request $request, $formClass, $entityClass)
 {
     $form = $this->factory->create(new $formClass(), new $entityClass());
     $arr = json_decode($request->getContent(), true);
     $parsed = [];
     parse_str(http_build_query($arr), $parsed);
     $request->attributes->add($parsed);
     $request->request->add($parsed);
     $form->handleRequest($request);
     $errors = [];
     foreach ($form->getErrors(true, true) as $err) {
         $errors[$form->getConfig()->getName() . '_' . $err->getOrigin()->getConfig()->getName()][] = $err->getMessage();
     }
     return new JsonResponse(['valid' => $form->isValid(), 'errors' => $errors]);
 }
 /**
  * @param Request $request
  * @param $issue
  * @return bool|Form|FormInterface
  */
 public function Issueeditstatus(Request $request, $issue)
 {
     $form = $this->FormFactory->create('form_issue_registration', $issue);
     if ($request->getMethod() == 'POST') {
         $form->handleRequest($request);
         if ($form->isValid()) {
             $issue = $form->getData();
             $em = $this->doctrine->getManager();
             $em->persist($issue);
             $em->flush();
             return true;
         }
     }
     return $form;
 }
 /**
  * @param Request $request
  * @return bool|Form|FormInterface
  */
 public function Projectcreate(Request $request)
 {
     $form = $this->FormFactory->create('form_project_registration', null);
     if ($request->getMethod() === 'POST') {
         $form->handleRequest($request);
         if ($form->isValid()) {
             $project = $form->getData();
             $em = $this->doctrine->getManager();
             $em->persist($project);
             $em->flush();
             return true;
         }
     }
     return $form;
 }
    /**
     * {@inheritdoc}
     */
    public function execute(BlockContextInterface $blockContext, Response $response = null)
    {
        $settings = $blockContext->getSettings();  
        $form = $this->formFactory->create('site_settings_form', $this->siteSettingManager->getSiteProperties('general'));

       
        if( 'POST' === $this->request->getMethod()) {
            $form = $this->formFactory->create('site_settings_form');
            $form->handleRequest($this->request);
            if($form->isValid()) {
                /** @var SiteSetting $siteProperties  **/
                $siteProperties = $form->getData();
                $picture = $form->get('picture')->getData();
                $siteProperties->pictureInformation = (null === $picture) ? null : $this->uploadPic($picture, 'main_pic');
                $this->siteSettingManager->saveGeneralSiteProperties($siteProperties);
                unset($form);
                $form = $this->formFactory->create('site_settings_form', $this->siteSettingManager->getSiteProperties('general'));
            } 
        } 
                   
        return $this->renderPrivateResponse($blockContext->getTemplate(), array(
            'block'         => $blockContext->getBlock(),
            'settings'      => $settings,
            'siteForm'      => $form->createView()
           
        ), $response);

    }
Beispiel #23
0
    public function testCreateConvertsTypeToUnderscoreSyntax()
    {
        $options = array('a' => '1', 'b' => '2');
        $resolvedOptions = array('a' => '2', 'b' => '3');
        $resolvedType = $this->getMockResolvedType();

        $this->registry->expects($this->once())
            ->method('getType')
            ->with('Vendor\Name\Space\MyProfileHTMLType')
            ->will($this->returnValue($resolvedType));

        $resolvedType->expects($this->once())
            ->method('createBuilder')
            ->with($this->factory, 'my_profile_html', $options)
            ->will($this->returnValue($this->builder));

        $this->builder->expects($this->any())
            ->method('getOptions')
            ->will($this->returnValue($resolvedOptions));

        $resolvedType->expects($this->once())
            ->method('buildForm')
            ->with($this->builder, $resolvedOptions);

        $this->builder->expects($this->once())
            ->method('getForm')
            ->will($this->returnValue('FORM'));

        $this->assertSame('FORM', $this->factory->create('Vendor\Name\Space\MyProfileHTMLType', null, $options));
    }
Beispiel #24
0
    /**
     * @group legacy
     */
    public function testCreateUsesTypeNameIfTypeGivenAsObject()
    {
        $options = array('a' => '1', 'b' => '2');
        $resolvedOptions = array('a' => '2', 'b' => '3');
        $resolvedType = $this->getMockResolvedType();

        $resolvedType->expects($this->once())
            ->method('getName')
            ->will($this->returnValue('TYPE'));

        $resolvedType->expects($this->once())
            ->method('createBuilder')
            ->with($this->factory, 'TYPE', $options)
            ->will($this->returnValue($this->builder));

        $this->builder->expects($this->any())
            ->method('getOptions')
            ->will($this->returnValue($resolvedOptions));

        $resolvedType->expects($this->once())
            ->method('buildForm')
            ->with($this->builder, $resolvedOptions);

        $this->builder->expects($this->once())
            ->method('getForm')
            ->will($this->returnValue('FORM'));

        $this->assertSame('FORM', $this->factory->create($resolvedType, null, $options));
    }
 /**
  * @param null  $data
  * @param array $options
  */
 public function createForm($data = null, array $options = [])
 {
     if (null !== $data) {
         $this->options['data'] = $data;
     }
     $this->form = $this->factory->create($this->name, null, array_merge($this->options, $options));
 }
Beispiel #26
0
 /**
  * @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);
 }
 /**
  * Create a category form.
  *
  * @param Category $category
  *
  * @return Form
  *
  */
 public function createForm(Category $category)
 {
     $route = $this->router->generate('prh_blog_category_create');
     if ($category->getId()) {
         $route = $this->router->generate('prh_blog_category_update', ['id' => $category->getId()]);
     }
     return $this->formFactory->create(new CategoryType(), $category, ['action' => $route, 'method' => 'POST']);
 }
 /**
  * @Template()
  * @param Request $request
  * @return array
  */
 public function addAction(Request $request)
 {
     $invoice = new Invoice();
     $customers = $this->getCustomersForUser();
     $rows = $this->getRowsForUser();
     $form = $this->formFactory->create(new InvoiceFormType($customers, $rows), $invoice);
     if ($request->isMethod('post')) {
         $form->submit($request);
         if ($form->isValid()) {
             $invoice->setUser($this->getCurrentUser());
             $this->entityManager->persist($invoice);
             $this->entityManager->flush();
             return new RedirectResponse($this->router->generate('invoicity_invoice_overview'));
         }
     }
     return array('form' => $form->createView());
 }
 public function processForm(WebsiteOptions $options, array $parameters, $method = 'PUT')
 {
     $form = $this->formFactory->create(new WebsiteOptionsType(), $options, array('method' => $method));
     $form->submit($parameters, 'PATCH' !== $method);
     if ($form->isValid()) {
         $options = $form->getData();
         $this->om->persist($options);
         $this->om->flush();
         $serializationContext = new SerializationContext();
         $serializationContext->setSerializeNull(true);
         return json_decode($this->serializer->serialize($options, 'json', $serializationContext));
     }
     /*else {
           return $this->getErrorMessages($form);
       }*/
     throw new \InvalidArgumentException();
 }
Beispiel #30
0
 /**
  * Create a post form.
  *
  * @param Post $post
  *
  * @return Form
  */
 public function createForm(Post $post)
 {
     $route = $this->router->generate('prh_blog_post_create');
     if ($post->getId()) {
         $route = $this->router->generate('prh_blog_post_update', ['id' => $post->getId()]);
     }
     return $this->formFactory->create(new PostType(), $post, ['action' => $route, 'method' => 'POST']);
 }