8000 [Form] Added a layer of 2.0 BC methods to FormView and updated UPGRAD… · Lumbendil/symfony@310f985 · GitHub
[go: up one dir, main page]

Skip to content

Commit 310f985

Browse files
committed
[Form] Added a layer of 2.0 BC methods to FormVi 8000 ew and updated UPGRADE and CHANGELOG
1 parent 5984b18 commit 310f985

File tree

3 files changed

+167
-46
lines changed

3 files changed

+167
-46
lines changed

UPGRADE-2.1.md

Lines changed: 63 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -224,30 +224,23 @@
224224
`buildViewBottomUp()` in `FormTypeInterface` and `FormTypeExtensionInterface`.
225225
Furthermore, `buildViewBottomUp()` was renamed to `finishView()`. At last,
226226
all methods in these types now receive instances of `FormBuilderInterface`
227-
and `FormViewInterface` where they received instances of `FormBuilder` and
228-
`FormView` before. You need to change the method signatures in your
229-
form types and extensions as shown below.
227+
where they received instances of `FormBuilder` before. You need to change the
228+
method signatures in your form types and extensions as shown below.
230229
231230
Before:
232231
233232
```
234233
use Symfony\Component\Form\FormBuilder;
235-
use Symfony\Component\Form\FormView;
236234
237235
public function buildForm(FormBuilder $builder, array $options)
238-
public function buildView(FormView $view, FormInterface $form)
239-
public function buildViewBottomUp(FormView $view, FormInterface $form)
240236
```
241237
242238
After:
243239
244240
```
245241
use Symfony\Component\Form\FormBuilderInterface;
246-
use Symfony\Component\Form\FormViewInterface;
247242
248243
public function buildForm(FormBuilderInterface $builder, array $options)
249-
public function buildView(FormViewInterface $view, FormInterface $form, array $options)
250-
public function finishView(FormViewInterface $view, FormInterface $form, array $options)
251244
```
252245
253246
* The method `createBuilder` was removed from `FormTypeInterface` for performance
@@ -383,41 +376,6 @@
383376
If address is an object in this case, the code given in "Before"
384377
works without changes.
385378
386-
* The methods in class `FormView` were renamed to match the naming used in
387-
`Form` and `FormBuilder`. The following list shows the old names on the
388-
left and the new names on the right:
389-
390-
* `set`: `setVar`
391-
* `has`: `hasVar`
392-
* `get`: `getVar`
393-
* `all`: `getVars`
394-
* `addChild`: `add`
395-
* `getChild`: `get`
396-
* `getChildren`: `all`
397-
* `removeChild`: `remove`
398-
* `hasChild`: `has`
399-
400-
The new method `addVars` was added to make the definition of multiple
401-
variables at once more convenient.
402-
403-
The method `hasChildren` was deprecated. You should use `count` instead.
404-
405-
Before:
406-
407-
```
408-
$view->set('help', 'A text longer than six characters');
409-
$view->set('error_class', 'max_length_error');
410-
```
411-
412-
After:
413-
414-
```
415-
$view->addVars(array(
416-
'help' => 'A text longer than six characters',
417-
'error_class' => 'max_length_error',
418-
));
419-
```
420-
421379
* Form and field names must now start with a letter, digit or underscore
422380
and only contain letters, digits, underscores, hyphens and colons.
423381
@@ -1069,6 +1027,67 @@
10691027
<?php echo $view['form']->block('widget_attributes') ?>
10701028
```
10711029
1030+
* The following methods in class `FormView` were deprecated and will be
1031+
removed in Symfony 2.3:
1032+
1033+
* `set`
1034+
* `has`
1035+
* `get`
1036+
* `all`
1037+
* `getVars`
1038+
* `addChild`
1039+
* `getChild`
1040+
* `getChildren`
1041+
* `removeChild`
1042+
* `hasChild`
1043+
* `hasChildren`
1044+
* `getParent`
1045+
* `hasParent`
1046+
* `setParent`
1047+
1048+
You should access the public properties `vars`, `children` and `parent`
1049+
instead.
1050+
1051+
Before:
1052+
1053+
```
1054+
$view->set('help', 'A text longer than six characters');
1055+
$view->set('error_class', 'max_length_error');
1056+
```
1057+
1058+
After:
1059+
1060+
```
1061+
$view->vars = array_replace($view->vars, array(
1062+
'help' => 'A text longer than six characters',
1063+
'error_class' => 'max_length_error',
1064+
));
1065+
```
1066+
1067+
Before:
1068+
1069+
```
1070+
echo $view->get('error_class');
1071+
```
1072+
1073+
After:
1074+
1075+
```
1076+
echo $view->vars['error_class'];
1077+
```
1078+
1079+
Before:
1080+
1081+
```
1082+
if ($view->hasChildren()) { ...
1083+
```
1084+
1085+
After:
1086+
1087+
```
1088+
if (count($view->children)) { ...
1089+
```
1090+
10721091
### Validator
10731092
10741093
* The methods `setMessage()`, `getMessageTemplate()` and

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,6 @@ CHANGELOG
134134
FormEvents::BIND_NORM_DATA
135135
* [BC BREAK] reversed the order of the first two arguments to `createNamed`
136136
and `createNamedBuilder` in `FormFactoryInterface`
137-
* [BC BREAK] adapted methods of FormView to match the naming used in
138-
FormInterface and FormBuilder
139137
* deprecated `getChildren` in Form and FormBuilder in favor of `all`
140138
* deprecated `hasChildren` in Form and FormBuilder in favor of `count`
141139
* FormBuilder now implements \IteratorAggregate
@@ -179,3 +177,4 @@ CHANGELOG
179177
* `isChoiceGroup`
180178
* `isChoiceSelected`
181179
* added method `block` to FormHelper and deprecated `renderBlock` instead
180+
* made FormView properties public and deprecated their accessor methods

src/Symfony/Component/Form/FormView.php

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,64 @@ public function getName()
6767
return $this->vars['name'];
6868
}
6969

70+
/**
71+
* @param string $name
72+
* @param mixed $value
73+
*
74+
* @return FormView The current view
75+
*
76+
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Access
77+
* the public property {@link vars} instead.
78+
*/
79+
public function set($name, $value)
80+
{
81+
$this->vars[$name] = $value;
82+
83+
return $this;
84+
}
85+
86+
/**
87+
* @param $name
88+
*
89+
* @return Boolean
90+
*
91+
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Access
92+
* the public property {@link vars} instead.
93+
*/
94+
public function has($name)
95+
{
96+
return array_key_exists($name, $this->vars);
97+
}
98+
99+
/**
100+
* @param $name
101+
* @param $default
102+
*
103+
* @return mixed
104+
*
105+
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Access
106+
* the public property {@link vars} instead.
107+
*/
108+
public function get($name, $default = null)
109+
{
110+
if (false === $this->has($name)) {
111+
return $default;
112+
}
113+
114+
return $this->vars[$name];
115+
}
116+
117+
/**
118+
* @return array
119+
*
120+
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Access
121+
* the public property {@link vars} instead.
122+
*/
123+
public function all()
124+
{
125+
return $this->vars;
126+
}
127+
70128
/**
71129
* Returns the values of all view variables.
72130
*
@@ -180,6 +238,51 @@ public function hasParent()
180238
return null !== $this->parent;
181239
}
182240

241+
/**
242+
* Sets the children view.
243+
*
244+
* @param array $children The children as instances of FormView
245+
*
246+
* @return FormView The current view
247+
*
248+
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Access
249+
* the public property {@link children} instead.
250+
*/
251+
public function setChildren(array $children)
252+
{
253+
$this->children = $children;
254+
255+
return $this;
256+
}
257+
258+
/**
259+
* Returns the children.
260+
*
261+
* @return array The children as instances of FormView
262+
*
263+
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Access
264+
* the public property {@link children} instead.
265+
*/
266+
public function getChildren()
267+
{
268+
return $this->children;
269+
}
270+
271+
/**
272+
* Returns a given child.
273+
*
274+
* @param string $name The name of the child
275+
*
276+
* @return FormView The child view
277+
*
278+
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Access
279+
* the public property {@link children} instead.
280+
*/
281+
public function getChild($name)
282+
{
283+
return $this->children[$name];
284+
}
285+
183286
/**
184287
* Returns whether this view has any children.
185288
*

0 commit comments

Comments
 (0)
0