Skip to content

Instantly share code, notes, and snippets.

@Raistlfiren
Created March 3, 2016 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raistlfiren/e1f1d9c771c080d95529 to your computer and use it in GitHub Desktop.
Save Raistlfiren/e1f1d9c771c080d95529 to your computer and use it in GitHub Desktop.
<?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