Skip to content

Commit

Permalink
Merge pull request #6 from acseo/v3.1
Browse files Browse the repository at this point in the history
V3.1
  • Loading branch information
romainguerrero authored Jan 11, 2019
2 parents e21bda1 + a3513e5 commit 1d8ff13
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 12 deletions.
1 change: 1 addition & 0 deletions Form/Extension/FieldTypeHelpExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace ACSEO\Bundle\DynamicFormBundle\Form\Extension;

use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
Expand Down
1 change: 1 addition & 0 deletions Form/Extension/FieldTypePictoExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace ACSEO\Bundle\DynamicFormBundle\Form\Extension;

use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
Expand Down
1 change: 1 addition & 0 deletions Form/Extension/FieldTypePopinExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace ACSEO\Bundle\DynamicFormBundle\Form\Extension;

use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
Expand Down
27 changes: 26 additions & 1 deletion Form/Field/FieldBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,32 @@ public function addAssociatedFielPostBindEvent($formFields, $builder)
*/
private function addSingleField($name, $field, $options, $builder)
{
$builder->add($name, $field->type, $options);
$builder->add($name, self::getFormTypeClass($field->type), $options);
}

/**
* @param string $fieldType
*/
public static function getFormTypeClass($fieldType)
{
switch ($fieldType) {
case 'checkbox':
return \Symfony\Component\Form\Extension\Core\Type\CheckboxType::class;
case 'choice':
return \Symfony\Component\Form\Extension\Core\Type\ChoiceType::class;
case 'date':
return \Symfony\Component\Form\Extension\Core\Type\DateType::class;
case 'file':
return \Symfony\Component\Form\Extension\Core\Type\FileType::class;
case 'fieldset':
return \ACSEO\Bundle\DynamicFormBundle\Form\Type\FieldsetType::class;
case 'text':
return \Symfony\Component\Form\Extension\Core\Type\TextType::class;
case 'textarea':
return \Symfony\Component\Form\Extension\Core\Type\TextareaType::class;
}

return $fieldType;
}

/**
Expand Down
7 changes: 4 additions & 3 deletions Form/FormManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@

namespace ACSEO\Bundle\DynamicFormBundle\Form;

use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\FormFactoryInterface;
use ACSEO\Bundle\DynamicFormBundle\Events;
use ACSEO\Bundle\DynamicFormBundle\Event\FormEvent;
use ACSEO\Bundle\DynamicFormBundle\Events;
use ACSEO\Bundle\DynamicFormBundle\Form\Provider\FormProviderInterface;
use ACSEO\Bundle\DynamicFormBundle\Form\Type\DynamicFormType;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\FormFactoryInterface;

/**
* Class FormManager
Expand Down
2 changes: 1 addition & 1 deletion Form/Type/DynamicFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
{
$formFields = json_decode($this->formStruct);

if (!count($formFields)) {
if (!count((array) $formFields)) {
throw new Exception('FormStruc is empty');
}

Expand Down
9 changes: 5 additions & 4 deletions Form/Type/FieldsetType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

namespace ACSEO\Bundle\DynamicFormBundle\Form\Type;

use ACSEO\Bundle\DynamicFormBundle\Form\Field\FieldBuilder;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* Class FieldsetType
Expand All @@ -15,9 +16,9 @@
class FieldsetType extends AbstractType
{
/**
* @param OptionsResolverInterface $resolver
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'title' => false,
Expand All @@ -34,7 +35,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
{
if (!empty($options['subforms'])) {
foreach ($options['subforms'] as $f) {
$builder->add($f['name'], $f['type'], $f['attr']);
$builder->add($f['name'], FieldBuilder::getFormTypeClass($f['type']), $f['attr']);
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions Form/Type/VirtualType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@

namespace ACSEO\Bundle\DynamicFormBundle\Form\Type;

use ACSEO\Bundle\DynamicFormBundle\Form\Field\FieldBuilder;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

/**
* Virtual Type : used for collection form type
Expand Down Expand Up @@ -45,7 +46,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
unset($this->options['data']);
}

$builder->add('value', $this->field->type, $this->options);
$builder->add('value', FieldBuilder::getFormTypeClass($this->field->type), $this->options);
}

/**
Expand Down

0 comments on commit 1d8ff13

Please sign in to comment.