for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace LAG\AdminBundle\Form\Factory;
use Exception;
use LAG\AdminBundle\Admin\AdminInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
class FormFactory
{
/**
* @var FormFactoryInterface
*/
protected $formFactory;
* FormFactory constructor.
*
* @param FormFactoryInterface $formFactory
public function __construct(FormFactoryInterface $formFactory)
$this->formFactory = $formFactory;
}
* @param $formType
* @param $entity
* @param AdminInterface $admin
* @return FormInterface
* @throws Exception
public function create($formType, $entity, AdminInterface $admin)
// an valid entity should be passed
if (!is_object($entity)) {
throw new Exception('Empty entity for form creation');
if (null === $formType) {
$form = $this->guessForm($admin);
} else {
// a form type is defined, we use the form factory
$form = $this
->formFactory
->create($formType, $entity);
return $form;
protected function guessForm(AdminInterface $admin)
$action = $admin->getCurrentAction();
->createNamed($admin->getName());
foreach ($action->getFields() as $field) {
$form->add($field->getName());