Beispiel #1
0
 public function testRemoveFields()
 {
     $dataMapper = $this->getMock('Symfony\\Component\\Form\\DataMapperInterface');
     $config = $this->getMock('Symfony\\Component\\Form\\FormConfigInterface');
     $config->expects($this->any())->method('getName')->will($this->returnValue('root'));
     $config->expects($this->any())->method('getCompound')->will($this->returnValue(true));
     $config->expects($this->any())->method('getDataMapper')->will($this->returnValue($dataMapper));
     $form = new Form($config);
     $config = $this->getMock('Symfony\\Component\\Form\\FormConfigInterface');
     $config->expects($this->any())->method('getName')->will($this->returnValue('child'));
     $form->add(new Form($config));
     FormHelper::removeFields(array(), $form);
     $this->assertFalse(isset($form['child']));
 }
Beispiel #2
0
 /**
  * Write a category, this method is used by both POST and PUT action methods.
  *
  * @param Request  $request Symfony request
  * @param int|null $id      A category identifier
  *
  * @return View|FormInterface
  */
 protected function handleWriteCategory($request, $id = null)
 {
     $category = $id ? $this->getCategory($id) : null;
     $form = $this->formFactory->createNamed(null, 'sonata_classification_api_form_category', $category, array('csrf_protection' => false));
     FormHelper::removeFields($request->request->all(), $form);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $category = $form->getData();
         $this->categoryManager->save($category);
         $view = \FOS\RestBundle\View\View::create($category);
         $serializationContext = SerializationContext::create();
         $serializationContext->setGroups(array('sonata_api_read'));
         $serializationContext->enableMaxDepthChecks();
         $view->setSerializationContext($serializationContext);
         return $view;
     }
     return $form;
 }