Created
March 3, 2016 15:52
-
-
Save Raistlfiren/e1f1d9c771c080d95529 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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