function it_builds_view(FormConfigInterface $config, FormView $view, FormInterface $form, FormInterface $prototype)
 {
     $form->getConfig()->willReturn($config);
     $config->getAttribute('prototypes')->willReturn(['configuration_kind' => $prototype]);
     $prototype->createView($view)->shouldBeCalled();
     $this->buildView($view, $form, []);
 }
 public function testProgressToConfirm()
 {
     $this->form->submit(['_operation' => ['confirm' => '']]);
     $view = $this->form->createView();
     $this->assertCount(2, $view['_operation']);
     $this->assertArrayHasKey('back', $view['_operation']);
     $this->assertArrayHasKey('commit', $view['_operation']);
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function getData()
 {
     $data = array('form' => $this->form->createView(), 'element' => $this->element);
     if ($this->form->getData()) {
         $data['id'] = $this->element->getDataIndexer()->getIndex($this->form->getData());
     }
     return $data;
 }
Exemplo n.º 4
0
 public function testViewData()
 {
     $view = $this->form->createView();
     $choices = $view->vars['choices'];
     $data = array();
     foreach ($choices as $choice) {
         $data[] = $choice->data;
     }
     $query = $this->app['eccube.repository.mail_template']->createQueryBuilder('m')->orderBy('m.id', 'ASC')->getQuery();
     $res = $query->getResult();
     // order by されているか
     $this->assertEquals($data, $res);
 }
 public function changePasswordAction(Request $request)
 {
     $this->changePasswordForm->handleRequest($request);
     if ($this->changePasswordForm->isValid()) {
         $user = $this->tokenStorage->getToken()->getUser();
         $formData = $this->changePasswordForm->getData();
         $this->eventDispatcher->dispatch(AdminSecurityEvents::CHANGE_PASSWORD, new ChangePasswordEvent($user, $formData['plainPassword']));
         $request->getSession()->invalidate();
         $this->tokenStorage->setToken(null);
         $request->getSession()->getFlashBag()->set('success', 'admin.change_password_message.success');
         return new RedirectResponse($this->router->generate('fsi_admin_security_user_login'));
     }
     return $this->templating->renderResponse($this->changePasswordActionTemplate, array('form' => $this->changePasswordForm->createView()));
 }
 /**
  * {@inheritdoc}
  *
  * @Template
  * @AclAncestor("pim_enrich_variant_group_create")
  */
 public function createAction(Request $request)
 {
     if (!$request->isXmlHttpRequest()) {
         return new RedirectResponse($this->router->generate('pim_enrich_variant_group_index'));
     }
     $group = $this->groupFactory->createGroup('VARIANT');
     $group->setProductTemplate($this->productTemplateBuilder->createProductTemplate());
     if ($this->groupHandler->process($group)) {
         $request->getSession()->getFlashBag()->add('success', new Message('flash.variant group.created'));
         $url = $this->router->generate('pim_enrich_variant_group_edit', ['code' => $group->getCode()]);
         $response = ['status' => 1, 'url' => $url];
         return new Response(json_encode($response));
     }
     return ['form' => $this->groupForm->createView()];
 }
Exemplo n.º 7
0
 /**
  * Creates a view.
  *
  * @param FormView $parent The parent view
  *
  * @return FormView The view
  */
 public function createView(FormView $parent = null)
 {
     if (null === $parent && $this->parent) {
         $parent = $this->parent->createView();
     }
     $view = new FormView();
     $view->setParent($parent);
     $types = (array) $this->types;
     foreach ($types as $type) {
         $type->buildView($view, $this);
         foreach ($type->getExtensions() as $typeExtension) {
             $typeExtension->buildView($view, $this);
         }
     }
     $childViews = array();
     foreach ($this->children as $key => $child) {
         $childViews[$key] = $child->createView($view);
     }
     $view->setChildren($childViews);
     foreach ($types as $type) {
         $type->buildViewBottomUp($view, $this);
         foreach ($type->getExtensions() as $typeExtension) {
             $typeExtension->buildViewBottomUp($view, $this);
         }
     }
     return $view;
 }
Exemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function createView(FormViewInterface $parent = null)
 {
     if (null === $parent && $this->parent) {
         $parent = $this->parent->createView();
     }
     $view = new FormView($this->config->getName());
     $view->setParent($parent);
     $types = (array) $this->config->getTypes();
     $options = $this->config->getOptions();
     foreach ($types as $type) {
         $type->buildView($view, $this, $options);
         foreach ($type->getExtensions() as $typeExtension) {
             $typeExtension->buildView($view, $this, $options);
         }
     }
     foreach ($this->children as $child) {
         $view->add($child->createView($view));
     }
     foreach ($types as $type) {
         $type->finishView($view, $this, $options);
         foreach ($type->getExtensions() as $typeExtension) {
             $typeExtension->finishView($view, $this, $options);
         }
     }
     return $view;
 }
Exemplo n.º 9
0
 /**
  * @param FormInterface $form
  *
  * @return array
  */
 public function convertMeta(FormInterface $form)
 {
     $formView = $form->createView();
     $fields = array();
     foreach ($formView->children as $name => $child) {
         $fields[$name] = array('default' => $child->vars['data'], 'label' => $child->vars['label'], 'required' => $child->vars['required']);
         if (in_array('checkbox', $child->vars['block_prefixes'])) {
             $fields[$name]['type'] = 'checkbox';
         } else {
             if (in_array('password', $child->vars['block_prefixes'])) {
                 $fields[$name]['type'] = 'password';
             } elseif (in_array('choice', $child->vars['block_prefixes'])) {
                 $fields[$name]['type'] = 'choice';
                 $fields[$name]['choices'] = array_values($child->vars['choices']);
             } elseif (in_array('text', $child->vars['block_prefixes'])) {
                 $fields[$name]['type'] = 'text';
             } elseif (in_array('number', $child->vars['block_prefixes'])) {
                 $fields[$name]['type'] = 'text';
             } else {
                 $fields[$name]['type'] = 'form';
                 $fields[$name]['children'] = $this->convertMeta($form->get($name));
             }
         }
     }
     return $fields;
 }
Exemplo n.º 10
0
 /**
  * Edit a group
  *
  * TODO : find a way to use param converter with interfaces
  *
  * @param Group $group
  *
  * @Template
  * @AclAncestor("pim_enrich_group_edit")
  *
  * @return array
  */
 public function editAction(Group $group)
 {
     if ($this->groupHandler->process($group)) {
         $this->request->getSession()->getFlashBag()->add('success', new Message('flash.group.updated'));
     }
     return ['form' => $this->groupForm->createView(), 'currentGroup' => $group->getId()];
 }
Exemplo n.º 11
0
 public function testViewData()
 {
     $view = $this->form->createView();
     $choices = $view->vars['choices'];
     // empty_value
     $this->assertEquals($view->vars['empty_value'], 'form.pref.empty_value');
     $data = array();
     // attrなど含まれているので
     foreach ($choices as $choice) {
         $data[] = $choice->data;
     }
     $query = $this->app['eccube.repository.master.pref']->createQueryBuilder('p')->orderBy('p.rank', 'ASC')->getQuery();
     $pref = $query->getResult();
     // order by されているか
     $this->assertEquals($data, $pref);
 }
Exemplo n.º 12
0
 function it_builds_view(FormView $view, FormInterface $form, FormConfigInterface $formConfig)
 {
     $form->getConfig()->shouldBeCalled()->willReturn($formConfig);
     $formConfig->getAttribute('prototypes')->shouldBeCalled()->willReturn(['type' => $form]);
     $form->createView($view)->shouldBeCalled();
     $this->buildView($view, $form, []);
 }
Exemplo n.º 13
0
 /**
  * {@inheritdoc}
  */
 public function createView(FormView $parent = null)
 {
     if (null === $parent && $this->parent) {
         $parent = $this->parent->createView();
     }
     return $this->config->getType()->createView($this, $parent);
 }
 /**
  * @DI\Observe("widget_badge_usage_configuration")
  *
  * @param ConfigureWidgetEvent $event
  */
 public function onConfig(ConfigureWidgetEvent $event)
 {
     $badgeWidgetConfig = $this->badgeWidgetManager->getBadgeUsageConfigForInstance($event->getInstance());
     $this->badgeUsageForm->setData($badgeWidgetConfig);
     $content = $this->templating->render('IcapBadgeBundle:Widget:badge_usage_config.html.twig', ['form' => $this->badgeUsageForm->createView(), 'instance' => $event->getInstance()]);
     $event->setContent($content);
 }
Exemplo n.º 15
0
 /**
  * @return FormView
  */
 public function getView()
 {
     if (!$this->view) {
         $this->view = $this->form->createView();
         $this->onCreateView($this->view, $this);
     }
     return $this->view;
 }
 /**
  * @param \Symfony\Bundle\FrameworkBundle\Templating\EngineInterface $templating
  * @param \Symfony\Component\Form\FormInterface $form
  * @param \Symfony\Component\Form\FormView $formView
  * @param \Symfony\Component\HttpFoundation\Request $request
  * @param \Symfony\Component\HttpFoundation\Response $response
  */
 function it_render_template_with_change_password_form($templating, $form, $formView, $request, $response)
 {
     $form->handleRequest($request)->shouldBeCalled();
     $form->isValid()->shouldBeCalled()->willReturn(false);
     $form->createView()->shouldBeCalled()->willReturn($formView);
     $templating->renderResponse('FSiAdminSecurityBundle:Admin:change_password.html.twig', array('form' => $formView))->shouldBeCalled()->willReturn($response);
     $this->changePasswordAction($request)->shouldReturn($response);
 }
Exemplo n.º 17
0
 /**
  * @param int $idCategory
  * @param \Symfony\Component\Form\FormInterface $form
  *
  * @return array
  */
 protected function getViewData($idCategory, FormInterface $form)
 {
     $locale = $this->getFactory()->getCurrentLocale();
     $categoryEntity = $this->getFactory()->getCategoryQueryContainer()->queryCategoryById($idCategory)->findOne();
     $productCategoryTable = $this->getFactory()->createProductCategoryTable($locale, $idCategory);
     $productTable = $this->getFactory()->createProductTable($locale, $idCategory);
     return ['idCategory' => $idCategory, 'form' => $form->createView(), 'productCategoriesTable' => $productCategoryTable->render(), 'productsTable' => $productTable->render(), 'showProducts' => false, 'currentCategory' => $categoryEntity->toArray(), 'paths' => $this->getPaths($categoryEntity, $locale), 'products' => $this->getProducts($categoryEntity, $locale), 'blocks' => $this->getBlocks($categoryEntity, $locale)];
 }
Exemplo n.º 18
0
 function it_builds_view(FormConfigInterface $config, FormView $view, FormInterface $form, FormInterface $formTable, FormInterface $formUserRegistration)
 {
     $prototypes = ['dataFetchers' => ['user_registration' => $formUserRegistration], 'renderers' => ['table' => $formTable]];
     $config->getAttribute('prototypes')->willReturn($prototypes);
     $form->getConfig()->willReturn($config);
     $formTable->createView($view)->shouldBeCalled();
     $formUserRegistration->createView($view)->shouldBeCalled();
     $this->buildView($view, $form, []);
 }
Exemplo n.º 19
0
 /**
  * @param Request $request
  * @param $form
  * @return FormView, bool
  */
 public function valid(Request $request, FormInterface $form)
 {
     $isValid = false;
     if ($request->getMethod() == 'POST') {
         $form->handleRequest($request);
         $isValid = $form->isValid();
     }
     return [$form->createView(), $isValid];
 }
Exemplo n.º 20
0
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     // the "prototype" var holds group form prototype
     // while the "prototypes" var is an associative array
     // of fieldName => filterPrototype pairs
     $view->vars['prototypes'] = array_map(function ($form) use($view) {
         return $form->createView($view);
     }, $form->getConfig()->getAttribute('prototypes'));
 }
 public function editAction(Request $request, $configurationId)
 {
     $configuration = $this->getConfigurationOr404($configurationId);
     if ($this->formHandler->process($configuration, $request)) {
         $this->formHandler->onSuccess();
         return new RedirectResponse($this->router->generate('aureja_job_queue_configurations'));
     }
     return $this->templating->renderResponse('AurejaJobQueueBundle:JobConfiguration:edit.html.twig', ['form' => $this->form->createView()]);
 }
Exemplo n.º 22
0
 /**
  *
  * @param FormInterface $form
  * @param array $formData
  */
 public function commonTest(FormInterface $form, $formData)
 {
     $this->assertTrue($form->isSynchronized());
     $view = $form->createView();
     $children = $view->children;
     foreach (array_keys($formData) as $key) {
         $this->assertArrayHasKey($key, $children);
     }
 }
 /**
  * {@inheritdoc}
  *
  * TODO: find a way to use param converter with interfaces
  *
  * @AclAncestor("pim_enrich_variant_group_edit")
  * @Template
  */
 public function editAction(Group $group)
 {
     if (!$group->getType()->isVariant()) {
         throw new NotFoundHttpException(sprintf('Variant group with id %d not found.', $group->getId()));
     }
     if ($this->groupHandler->process($group)) {
         $this->request->getSession()->getFlashBag()->add('success', new Message('flash.variant group.updated'));
     }
     return ['form' => $this->groupForm->createView(), 'currentGroup' => $group->getId(), 'attributesForm' => $this->getAvailableAttributesForm($group)->createView()];
 }
 /**
  * @param \OAuth2\Endpoint\Authorization      $authorization
  * @param \Psr\Http\Message\ResponseInterface $response
  */
 private function prepareResponse(Authorization $authorization, ResponseInterface &$response)
 {
     $content = $this->template_engine->render('/spomky-labs/oauth2-server/authorization/template/Authorization/authorization.html.twig', ['form' => $this->form->createView(), 'authorization' => $authorization]);
     $body = new Stream('php://temp', 'wb+');
     $body->write($content);
     $response = new Response($body);
     if (null !== $this->x_frame_options) {
         $response = $response->withHeader('X-Frame-Options', $this->x_frame_options);
     }
 }
 /**
  * Render admin form and tag response with status 400 if form is badly completed
  *
  * @param FormInterface $form
  * @param array         $params additional view parameters
  * @param Response|null $response
  * @param string        $template
  *
  * @return Response
  */
 protected function renderAdminForm(FormInterface $form, array $params = array(), $response = null, $template = self::TEMPLATE)
 {
     if (is_null($response)) {
         $code = Response::HTTP_OK;
         if ($form->isSubmitted() && !$form->isValid()) {
             $code = Response::HTTP_UNPROCESSABLE_ENTITY;
         }
         $response = new Response('', $code, array('Content-type' => 'text/html; charset=utf-8'));
     }
     $params = array_merge($params, array('form' => $form->createView()));
     return $this->render($template, $params, $response);
 }
Exemplo n.º 26
0
 /**
  * {@inheritdoc}
  */
 public function createView(FormView $parent = null)
 {
     if (null === $parent && $this->parent) {
         $parent = $this->parent->createView();
     }
     $type = $this->config->getType();
     $options = $this->config->getOptions();
     $view = $type->createView($this, $parent);
     $type->buildView($view, $this, $options);
     $type->finishView($view, $this, $options);
     return $view;
 }
Exemplo n.º 27
0
 /**
  * {@inheritdoc}
  */
 public function handle(GridInterface $grid, FormInterface $form = null, FormInterface $batchForm = null)
 {
     $valid = $form !== null && $form->isValid();
     $view = $this->handler->handle($grid, $valid ? $form->get('filters')->getData() : [], $valid ? $form->get('sorting')->getData() : [], $valid ? ['page' => $form->get('page')->getData(), 'limit' => $form->get('limit')->getData()] : []);
     if ($form !== null) {
         $view->setForm($form->createView());
     }
     if ($batchForm !== null) {
         $view->setBatchForm($batchForm->createView());
     }
     return $view;
 }
Exemplo n.º 28
0
 /**
  * @param Request       $request
  * @param FormInterface $form
  *
  * @param Page          $page
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function processPageForm(Request $request, $form, $page = null)
 {
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $page = $form->getData();
         $em = $this->get('doctrine.orm.entity_manager');
         $em->persist($page);
         $em->flush();
         return $this->redirect($this->generateUrl('taforum_admin_page', array('pagePermalink' => $page->getPagePermalink())));
     }
     return $this->render('TerAelisForumBundle:Page:admin_page_edit.html.twig', array('page' => !empty($page) ? $page : null, 'form' => $form->createView()));
 }
Exemplo n.º 29
0
    /**
     * Creates a view.
     *
     * @param FormView $parent The parent view
     *
     * @return FormView The view
     */
    public function createView(FormView $parent = null)
    {
        if (null === $parent && $this->parent) {
            $parent = $this->parent->createView();
        }

        $view = new FormView();

        $view->setParent($parent);

        $types = (array) $this->types;

        foreach ($types as $type) {
            $type->buildView($view, $this);

            foreach ($type->getExtensions() as $typeExtension) {
                $typeExtension->buildView($view, $this);
            }
        }

        $childViews = array();

        foreach ($this->children as $key => $child) {
            $childViews[$key] = $child->createView($view);
        }

        if (null !== $prototype = $view->get('prototype')) {
            $protoView = $prototype->getForm()->createView($view);
            $protoTypes = $protoView->get('types');
            $protoTypes[] = 'prototype';
            $childViews[$prototype->getName()] = $protoView
                ->set('types', $protoTypes)
                ->set('proto_id', $view->get('id').'_prototype');
            ;
        }

        $view->setChildren($childViews);

        foreach ($types as $type) {
            $type->buildViewBottomUp($view, $this);

            foreach ($type->getExtensions() as $typeExtension) {
                $typeExtension->buildViewBottomUp($view, $this);
            }
        }

        return $view;
    }
Exemplo n.º 30
0
 /**
  * {@inheritdoc}
  */
 public function createView(FormView $parent = null)
 {
     if (null === $parent && $this->parent) {
         $parent = $this->parent->createView();
     }
     $type = $this->config->getType();
     $options = $this->config->getOptions();
     // The methods createView(), buildView() and finishView() are called
     // explicitly here in order to be able to override either of them
     // in a custom resolved form type.
     $view = $type->createView($this, $parent);
     $type->buildView($view, $this, $options);
     foreach ($this->children as $name => $child) {
         $view->children[$name] = $child->createView($view);
     }
     $type->finishView($view, $this, $options);
     return $view;
 }