Skip to content

Commit f516801

Browse files
committed
[Form] Deprecated FormTypeInterface::getName() and passing of type instances
1 parent dd7583d commit f516801

File tree

92 files changed

+1980
-974
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+1980
-974
lines changed

UPGRADE-2.8.md

Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Form
1212
Before:
1313

1414
```php
15-
$form = $this->createForm('form', $article, array('cascade_validation' => true))
15+
$form = $this->createFormBuilder($article, array('cascade_validation' => true))
1616
->add('author', new AuthorType())
1717
->getForm();
1818
```
@@ -22,7 +22,7 @@ Form
2222
```php
2323
use Symfony\Component\Validator\Constraints\Valid;
2424

25-
$form = $this->createForm('form', $article)
25+
$form = $this->createFormBuilder($article)
2626
->add('author', new AuthorType(), array(
2727
'constraints' => new Valid(),
2828
))
@@ -42,6 +42,101 @@ Form
4242
private $author;
4343
}
4444
```
45+
46+
* Type names were deprecated and will be removed in Symfony 3.0. Instead of
47+
referencing types by name, you should reference them by their
48+
fully-qualified class name (FQCN) instead. With PHP 5.5 or later, you should
49+
use the "class" constant for that:
50+
51+
Before:
52+
53+
```php
54+
$form = $this->createFormBuilder()
55+
->add('name', 'text')
56+
->add('age', 'integer')
57+
->getForm();
58+
```
59+
60+
After:
61+
62+
```php
63+
use Symfony\Component\Form\Extension\Core\Type\FormType;
64+
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
65+
use Symfony\Component\Form\Extension\Core\Type\TextType;
66+
67+
$form = $this->createFormBuilder()
68+
->add('name', TextType::class)
69+
->add('age', IntegerType::class)
70+
->getForm();
71+
```
72+
73+
As a further consequence, the method `FormTypeInterface::getName()` was
74+
deprecated and will be removed in Symfony 3.0. You should remove this method
75+
from your form types.
76+
77+
If you define your form types in the Dependency Injection configuration, you
78+
should further remove the "alias" attribute:
79+
80+
Before:
81+
82+
```xml
83+
<service id="my.type" class="Vendor\Type\MyType">
84+
<tag name="form.type" alias="mytype" />
85+
</service>
86+
```
87+
88+
After:
89+
90+
```xml
91+
<service id="my.type" class="Vendor\Type\MyType">
92+
<tag name="form.type" />
93+
</service>
94+
```
95+
96+
* Returning type instances from `FormTypeInterface::getParent()` is deprecated
97+
and will not be supported anymore in Symfony 3.0. Return the fully-qualified
98+
class name of the parent type class instead.
99+
100+
Before:
101+
102+
```php
103+
class MyType
104+
{
105+
public function getParent()
106+
{
107+
return new ParentType();
108+
}
109+
}
110+
```
111+
112+
After:
113+
114+
```php
115+
class MyType
116+
{
117+
public function getParent()
118+
{
119+
return ParentType::class;
120+
}
121+
}
122+
```
123+
124+
* Passing type instances to `Form::add()`, `FormBuilder::add()` and the
125+
`FormFactory::create*()` methods is deprecated and will not be supported
126+
anymore in Symfony 3.0. Pass the fully-qualified class name of the type
127+
instead.
128+
129+
Before:
130+
131+
```php
132+
$form = $this->createForm(new MyType());
133+
```
134+
135+
After:
136+
137+
```php
138+
$form = $this->createForm(MyType::class);
139+
```
45140

46141
Translator
47142
----------

src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ public static function createChoiceName($choice, $key, $value)
9494
* Gets important parts from QueryBuilder that will allow to cache its results.
9595
* For instance in ORM two query builders with an equal SQL string and
9696
* equal parameters are considered to be equal.
97-
*
97+
*
9898
* @param object $queryBuilder
99-
*
99+
*
100100
* @return array|false Array with important QueryBuilder parts or false if
101101
* they can't be determined
102-
*
102+
*
103103
* @internal This method is public to be usable as callback. It should not
104104
* be used in user code.
105105
*/
@@ -335,6 +335,6 @@ abstract public function getLoader(ObjectManager $manager, $queryBuilder, $class
335335

336336
public function getParent()
337337
{
338-
return 'choice';
338+
return 'Symfony\Component\Form\Extension\Core\Type\ChoiceType';
339339
}
340340
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy