Skip to content

Instantly share code, notes, and snippets.

@merk
Created November 22, 2013 11:37
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 merk/7598564 to your computer and use it in GitHub Desktop.
Save merk/7598564 to your computer and use it in GitHub Desktop.
FormFactoryTrait
<?php
/**
* This file is part of the Infinite Helper library
*
* (c) Infinite Networks Pty Ltd <http://www.infinite.net.au>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Infinite\Traits;
use Symfony\Component\HttpFoundation\Request;
trait FormFactoryTrait
{
/**
* Note: this variable is ONLY USED FOR TESTING.
*/
public $formFactory;
/**
* @DI\LookupMethod("form.factory")
*
* @return \Symfony\Component\Form\FormFactoryInterface
*/
protected function getFormFactory()
{
return $this->formFactory;
}
/**
* Creates a form.
*
* @param string $type
* @param mixed $data
* @param Request $request
* @param array $options
* @return \Symfony\Component\Form\FormInterface
*/
protected function createForm($type, $data = null, Request $request = null, array $options = array())
{
$form = $this->getFormFactory()->create($type, $data, $options);
if ($request) {
$form->handleRequest($request);
}
return $form;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment