Created
November 22, 2013 11:37
-
-
Save merk/7598564 to your computer and use it in GitHub Desktop.
FormFactoryTrait
This file contains 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 | |
/** | |
* 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