Commit c8e61fc2 authored by quazardous's avatar quazardous Committed by Fabien Potencier

add a namedForm() method in FormTrait

parent 5a7a491f
...@@ -17,6 +17,7 @@ use Symfony\Component\Form\FormBuilder; ...@@ -17,6 +17,7 @@ use Symfony\Component\Form\FormBuilder;
* Form trait. * Form trait.
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
* @author David Berlioz <berliozdavid@gmail.com>
*/ */
trait FormTrait trait FormTrait
{ {
...@@ -38,4 +39,25 @@ trait FormTrait ...@@ -38,4 +39,25 @@ trait FormTrait
return $this['form.factory']->createBuilder($type, $data, $options); return $this['form.factory']->createBuilder($type, $data, $options);
} }
/**
* Creates and returns a named form builder instance.
*
* @param string $name
* @param mixed $data The initial data for the form
* @param array $options Options for the form
* @param string|FormTypeInterface $type Type of the form
*
* @return \Symfony\Component\Form\FormBuilder
*/
public function namedForm($name, $data = null, array $options = array(), $type = null)
{
if (null === $type) {
// BC with Symfony < 2.8
$type = class_exists('Symfony\Component\Form\Extension\Core\Type\RangeType') ? 'Symfony\Component\Form\Extension\Core\Type\FormType' : 'form';
}
return $this['form.factory']->createNamedBuilder($name, $type, $data, $options);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment