Ejemplo n.º 1
0
 function it_builds_a_form(MetadataFactory $metadataFactory, BuilderInterface $formBuilder, Form $form, Text $text)
 {
     $classMetadata = $this->getClassMetadata();
     $data = $this->getData();
     $metadataFactory->getMetadataForClass('Indigo\\Fieldset\\Stubs\\Entity')->willReturn($classMetadata);
     $formBuilder->generate($data)->willReturn([$text]);
     $form->setContents([$text])->shouldBeCalled();
     $this->buildForm('Indigo\\Fieldset\\Stubs\\Entity', $form);
 }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
0
 /**
  * Renders the whole form, wrapping a table in <form> tags.
  *
  * @param  Form $form
  *
  * @return string
  *
  * @since 2.0
  */
 public function renderForm(Form $form)
 {
     $content = '';
     foreach ($form as $element) {
         $content .= $this->render($element);
     }
     $form->setAttribute('role', 'form');
     return Html::tag('form', $form->getAttributes(), $content);
 }
 /**
  * Creates a new comment form
  *
  * @return Form
  */
 protected function createCommentForm()
 {
     $form = new Form();
     $form['comment'] = (new Input\Textarea('comment'))->setLabel(gettext('Comment'));
     $form['internal'] = (new Input\Checkbox('internal'))->setLabel(gettext('Is internal?'));
     $form->setAttribute('method', 'POST');
     $form['submit'] = (new Input\Button('submit'))->setAttribute('type', 'submit')->setContents(gettext('Add comment'));
     return $form;
 }
Ejemplo n.º 5
0
 /**
  * Get the fieldset name
  *
  * @return string
  */
 public function get_name()
 {
     return $this->form->getName();
 }
Ejemplo n.º 6
0
 /**
  * Populates a form for an object
  *
  * @param object $object
  * @param Form   $form
  */
 public function populateForm($object, Form $form)
 {
     $classMetadata = $this->metadataFactory->getMetadataForClass(get_class($object));
     $data = [];
     foreach ($classMetadata->propertyMetadata as $propertyMetadata) {
         if (!isset($propertyMetadata->type)) {
             continue;
         }
         $data[$propertyMetadata->name] = $propertyMetadata->getValue($object);
     }
     $form->populate($data);
 }
Ejemplo n.º 7
0
 /**
  * Renders the whole form, wrapping a table in <form> tags.
  *
  * @param  Form $form
  *
  * @return string
  *
  * @since 2.0
  */
 public function renderForm(Form $form)
 {
     foreach ($form as $element) {
         $this->render($element);
     }
     $tableRender = new SimpleTable();
     $tableContent = $tableRender->renderTable($this->table);
     return Html::tag('form', $form->getAttributes(), $tableContent);
 }