Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
namespace FA\Shared\CoreBundle\Form\Handler;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormFactory;
class FormHandler
{
/**
* @var FormFactory
*/
protected $formFactory;
/**
* @var AbstractType
*/
protected $formType;
public function __construct(AbstractType $formType, FormFactory $formFactory)
{
$this->formType = $formType;
$this->formFactory = $formFactory;
}
/**
* @param $entity
* @param array $options
* @param null $label
* @return \Symfony\Component\Form\Form|\Symfony\Component\Form\FormInterface
*/
public function initializeForm($entity, $options = array(), $label = null)
{
$form = $this->formFactory->create(
$this->formType,
$entity,
$options
);
if (is_null($label)) {
return $form;
}
$form->add('submit', 'submit', array('label' => $label));
return $form;
}
/**
* @param $name
* @return \Symfony\Component\Form\Form|\Symfony\Component\Form\FormInterface
*/
public function createDeleteForm($name)
{
$form = $this->formFactory
->createNamedBuilder($name, 'form', null, ['method' => 'DELETE'])
->getForm();
return $form;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment