Skip to content

Commit 6bf3fbb

Browse files
committed
add a NamedFormTrait helper trait
1 parent e0375a2 commit 6bf3fbb

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
/.buildpath
33
/.project
44
/.*.md.html
5+
/vendor/
6+
/composer.lock

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"require-dev" : {
2424
"kriswallsmith/assetic" : "^1.0",
2525
"mheap/Silex-Assetic" : "*@dev",
26-
"quazardous/silex-console" : "*@dev"
26+
"quazardous/silex-console" : "*@dev",
27+
"symfony/form": "^3.0"
2728
},
2829
"autoload" : {
2930
"psr-4" : {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Quazardous\Silex\Application;
4+
5+
use Symfony\Component\Form\FormBuilder;
6+
7+
/**
8+
* Named Form trait.
9+
*
10+
*/
11+
trait NamedFormTrait
12+
{
13+
/**
14+
* Creates and returns a named form builder instance.
15+
*
16+
* @param string $name
17+
* @param mixed $data The initial data for the form
18+
* @param array $options Options for the form
19+
* @param string|FormTypeInterface $type Type of the form
20+
*
21+
* @return \Symfony\Component\Form\FormBuilder
22+
*/
23+
public function namedForm($name, $data = null, array $options = array(), $type = null)
24+
{
25+
if (null === $type) {
26+
// BC with Symfony < 2.8
27+
$type = class_exists('Symfony\Component\Form\Extension\Core\Type\RangeType') ? 'Symfony\Component\Form\Extension\Core\Type\FormType' : 'form';
28+
}
29+
30+
return $this['form.factory']->createNamedBuilder($name, $type, $data, $options);
31+
}
32+
}

0 commit comments

Comments
 (0)