コード例 #1
0
ファイル: DocumentTypeTest.php プロジェクト: alebon/graviton
 /**
  * Test DocumentType::handlePreSubmitEvent()
  *
  * @return void
  */
 public function testHandlePreSubmitEvent()
 {
     $class = __CLASS__;
     $fields = [['name1', 'type1', ['options1']], ['name2', 'type2', ['options2']]];
     $submittedData = ['name1' => 'data1', 'name2' => 'data2'];
     $formDouble = $this->getMockBuilder('Symfony\\Component\\Form\\FormInterface')->disableOriginalConstructor()->getMock();
     $formDouble->expects($this->once())->method('isRequired')->willReturn(true);
     $sut = new DocumentType($this->fieldBuilderDouble, [$class => $fields]);
     $sut->initialize($class);
     $this->fieldBuilderDouble->expects($this->exactly(2))->method('supportsField')->withConsecutive(['type1', ['options1']], ['type2', ['options2']])->willReturn(true);
     $this->fieldBuilderDouble->expects($this->exactly(2))->method('buildField')->withConsecutive([$sut, $formDouble, 'name1', 'type1', ['options1'], 'data1'], [$sut, $formDouble, 'name2', 'type2', ['options2'], 'data2']);
     $sut->handlePreSubmitEvent(new FormEvent($formDouble, $submittedData));
 }
コード例 #2
0
ファイル: DocumentType.php プロジェクト: alebon/graviton
 /**
  * Handle "presubmit" event
  *
  * @param FormEvent $event Submit event
  * @return void
  */
 public function handlePreSubmitEvent(FormEvent $event)
 {
     if (empty($this->fieldMap[$this->dataClass])) {
         return;
     }
     $form = $event->getForm();
     $data = $event->getData();
     if (!$form->isRequired() && $data === null) {
         return;
     }
     foreach ($this->fieldMap[$this->dataClass] as $config) {
         list($name, $type, $options) = $config;
         if (!$this->fieldBuilder->supportsField($type, $options)) {
             throw new \LogicException(sprintf('Could not build field "%s" with options "%s"', $type, json_encode($options)));
         }
         $this->fieldBuilder->buildField($this, $form, $name, $type, $options, is_array($data) && isset($data[$name]) ? $data[$name] : null);
     }
 }