Пример #1
0
 /**
  * Builds a form for a class
  *
  * @param string $class
  * @param Form   $form
  */
 public function buildForm($class, Form $form)
 {
     $classMetadata = $this->metadataFactory->getMetadataForClass($class);
     $propertyMetadata = $classMetadata->propertyMetadata;
     $data = [];
     $attributes = $classMetadata->attributes;
     $attributes['action'] = $classMetadata->action;
     $attributes['method'] = $classMetadata->method;
     $form->setAttributes($attributes);
     foreach ($classMetadata->fieldsets as $name => $fieldset) {
         $fieldset['type'] = 'fieldset';
         $fields = $fieldset['fields'];
         unset($fieldset['fields']);
         foreach ($fields as &$field) {
             if (!isset($propertyMetadata[$field])) {
                 throw new \RuntimException(sprintf('%s is expected to have a(n) %s field', $class, $field));
             }
             $fieldset['content'][$field] = $this->buildFormField($propertyMetadata[$field]);
             unset($propertyMetadata[$field]);
         }
         $data[$name] = $fieldset;
     }
     // Process fields
     // If no fieldsets are in use, this processes all fields
     // Otherwise fieldset fields are processed above
     // (Ideally fieldsets should be used for all or none fields)
     foreach ($propertyMetadata as $propertyName => $pMetadata) {
         $data[$propertyName] = $this->buildFormField($pMetadata);
     }
     $generatedForm = $this->formBuilder->generate($data);
     $form->setContents($generatedForm);
 }
Пример #2
0
 function it_generates_a_form(MetadataFactory $metadataFactory, BuilderInterface $formBuilder, Text $text)
 {
     $classMetadata = $this->getClassMetadata();
     $data = $this->getData();
     $metadataFactory->getMetadataForClass('Indigo\\Fieldset\\Stubs\\Entity')->willReturn($classMetadata);
     $formBuilder->generate($data)->willReturn([$text]);
     $this->generateForm('Indigo\\Fieldset\\Stubs\\Entity')->shouldHaveType('Fuel\\Fieldset\\Form');
 }
Пример #3
0
 /**
  * Populates the given form with the needed fields
  *
  * @param Form $form
  *
  * @return Form
  */
 public static function populateForm(Form $form)
 {
     if (static::$builder === null) {
         static::setBuilder(new V1Model());
         static::$builder->setWrapperElement(null);
     }
     $elements = static::$builder->generate(get_called_class());
     return $form->setContents($elements);
 }