fjogeleit / dynamic-form-bundle
DynamicForm creates database driven forms and persist results
Installs: 991
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 2
Forks: 1
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=7.1.3
- doctrine/doctrine-bundle: ~1.4
- doctrine/doctrine-fixtures-bundle: ^2.3
- doctrine/orm: ^2.5
- hautelook/alice-bundle: ^2.3
- sensio/framework-extra-bundle: ~5.2
- sonata-project/admin-bundle: ~3.0
- symfony/symfony: ~4.1
Requires (Dev)
- tm/tooly-composer-script: ^1.0
- dev-master
- 0.9.1
- 0.9.0
- 0.8.0
- 0.7.0
- 0.6.4
- 0.6.3
- 0.6.2
- 0.6.1
- 0.6.0
- 0.5.0
- 0.4.0
- 0.3.19
- 0.3.18
- 0.3.17
- 0.3.16
- 0.3.15
- 0.3.14
- 0.3.13
- 0.3.11
- 0.3.10
- 0.3.9
- 0.3.8
- 0.3.7
- 0.3.6
- 0.3.5
- 0.3.4
- 0.3.3
- 0.3.2
- 0.3.1
- 0.3.0
- 0.2.19
- 0.2.18
- 0.2.17
- 0.2.16
- 0.2.15
- 0.2.14
- 0.2.13
- 0.2.12
- 0.2.11
- 0.2.10
- 0.2.9
- 0.2.8
- 0.2.7
- 0.2.6
- 0.2.5
- 0.2.4
- 0.2.3
- 0.2.1
- 0.2.0
- 0.1.16
- 0.1.15
- 0.1.13
- 0.1.12
- 0.1.11
- 0.1.10
- 0.1.9
- 0.1.8
- 0.1.7
- 0.1.6
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- dev-update-symfony-4
This package is auto-updated.
Last update: 2020-09-11 11:13:50 UTC
README
A Symfony bundle to create database driven dynamic Forms and save them.
- create Forms with an Backend like SonataAdmin Bundle
- improve Form usability with dynamic text-elements like headlines or text
- support different form-fields like input, textarea, checkbox-group, radio-group, file-input
- flexible extensible with custom FormTypes and FormType configurations
- it is passible to integrate subforms and save values as custom ORM Entities
Requirements
- PHP >= 5.6
- Composer
Install via Composer
composer require fjogeleit/dynamic-form-bundle
Configuration
dynamic_form:
file_upload_dir: 'uploads' # upload directory for FileValues with web/ as root-dir
form_field: # disable field options to configure
disable_options:
- 'disabled'
- 'label'
- 'placeholder'
- 'required'
Backend Routing
Activate the dynamic-form-bundle routes in your project routing.
dynamic_form:
resource: "@DynamicFormBundle/Controller/"
type: annotation
prefix: "dynamic-form"
Install SonataAdminBundle
See Sonata Project
Different ValueType-Supprt
Examples:
- String
- DateTime
- Entity
- simple Array
- Choice(s)
- Float
- ...
Integrate custom Subforms
Create the Symfony FormType
class ContactType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name', TextType::class);
$builder->add('email', TextType::class);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Contact::class,
'label' => false
]);
}
}
Create the ConfigurationObject for the new Subform
This Object has to implement the DynamicFormType "ConfigurationInterface".
use AppBundle\FormType\ContactType;
use DynamicFormBundle\Entity\DynamicResult\ResultValue\EntityValue;
use DynamicFormBundle\Services\FormType\ConfigurationInterface;
use DynamicFormBundle\Statics\FormFieldOptions\BaseOptions;
class ContactConfiguration implements ConfigurationInterface
{
/**
* @return string
*/
public function getName()
{
return 'contact';
}
/**
* @return string
*/
public function getFormTypeClass()
{
return ContactType::class;
}
/**
* @return string
*/
public function getValueClass()
{
return EntityValue::class;
}
/**
* @return array
*/
public function getAvailableOptions()
{
return BaseOptions::all();
}
}
It defines:
- the backend-naming of the field
- the new FormType that should be render in the frontend
- which kind of value would be save
-
- our ContactType save his values as Contact-Entity (data_class), so its value type is an EntityValue
- an array of option that could be configured for this field, like required.
at least configure the ContactConfiguration as Service with the TagName: "form.type_configuration"
services:
app.dynamic_form_type.contact.configuration:
class: 'AppBundle\Services\DynamicFormType\Configuration\ContactConfiguration'
tags:
- { name: 'form.type_configuration' }
Now the new Contact Subform is as new FormField in the backend available.
EntityValue
To use an custom Entity as "data_class" for DynamicForm subforms it has to extend the DynamicForm:AbstractEntity Class.
use Doctrine\ORM\Mapping as ORM;
use DynamicFormBundle\Entity\AbstractEntity;
/**
* @ORM\Entity
* @ORM\Table(name="contact")
*
* @package DynamicFormBundle\Tests\Functional\Fixtures\Entity
*/
class Contact extends AbstractEntity
{
/**
* @var string
*
* @ORM\Column(type="string")
*/
private $name;
/**
* @var string
*
* @ORM\Column(type="string")
*/
private $email;
/**
* @param string $name
* @param string $email
*/
public function __construct($name = null, $email = null)
{
$this->name = $name;
$this->email = $email;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*
* @return $this
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* @param string $email
*
* @return $this
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
}