Navigation Menu

Skip to content

Commit

Permalink
[Form] Added a layer of 2.0 BC methods to FormView and updated UPGRAD…
Browse files Browse the repository at this point in the history
…E and CHANGELOG
  • Loading branch information
webmozart committed Jul 21, 2012
1 parent 5984b18 commit 310f985
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 46 deletions.
107 changes: 63 additions & 44 deletions UPGRADE-2.1.md
Expand Up @@ -224,30 +224,23 @@
`buildViewBottomUp()` in `FormTypeInterface` and `FormTypeExtensionInterface`.
Furthermore, `buildViewBottomUp()` was renamed to `finishView()`. At last,
all methods in these types now receive instances of `FormBuilderInterface`
and `FormViewInterface` where they received instances of `FormBuilder` and
`FormView` before. You need to change the method signatures in your
form types and extensions as shown below.
where they received instances of `FormBuilder` before. You need to change the
method signatures in your form types and extensions as shown below.

Before:

```
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormView;
public function buildForm(FormBuilder $builder, array $options)
public function buildView(FormView $view, FormInterface $form)
public function buildViewBottomUp(FormView $view, FormInterface $form)
```

After:

```
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormViewInterface;
public function buildForm(FormBuilderInterface $builder, array $options)
public function buildView(FormViewInterface $view, FormInterface $form, array $options)
public function finishView(FormViewInterface $view, FormInterface $form, array $options)
```

* The method `createBuilder` was removed from `FormTypeInterface` for performance
Expand Down Expand Up @@ -383,41 +376,6 @@
If address is an object in this case, the code given in "Before"
works without changes.

* The methods in class `FormView` were renamed to match the naming used in
`Form` and `FormBuilder`. The following list shows the old names on the
left and the new names on the right:

* `set`: `setVar`
* `has`: `hasVar`
* `get`: `getVar`
* `all`: `getVars`
* `addChild`: `add`
* `getChild`: `get`
* `getChildren`: `all`
* `removeChild`: `remove`
* `hasChild`: `has`

The new method `addVars` was added to make the definition of multiple
variables at once more convenient.

The method `hasChildren` was deprecated. You should use `count` instead.

Before:

```
$view->set('help', 'A text longer than six characters');
$view->set('error_class', 'max_length_error');
```

After:

```
$view->addVars(array(
'help' => 'A text longer than six characters',
'error_class' => 'max_length_error',
));
```

* Form and field names must now start with a letter, digit or underscore
and only contain letters, digits, underscores, hyphens and colons.

Expand Down Expand Up @@ -1069,6 +1027,67 @@
<?php echo $view['form']->block('widget_attributes') ?>
```

* The following methods in class `FormView` were deprecated and will be
removed in Symfony 2.3:

* `set`
* `has`
* `get`
* `all`
* `getVars`
* `addChild`
* `getChild`
* `getChildren`
* `removeChild`
* `hasChild`
* `hasChildren`
* `getParent`
* `hasParent`
* `setParent`

You should access the public properties `vars`, `children` and `parent`
instead.

Before:

```
$view->set('help', 'A text longer than six characters');
$view->set('error_class', 'max_length_error');
```

After:

```
$view->vars = array_replace($view->vars, array(
'help' => 'A text longer than six characters',
'error_class' => 'max_length_error',
));
```

Before:

```
echo $view->get('error_class');
```

After:

```
echo $view->vars['error_class'];
```

Before:

```
if ($view->hasChildren()) { ...
```

After:

```
if (count($view->children)) { ...
```

### Validator

* The methods `setMessage()`, `getMessageTemplate()` and
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Component/Form/CHANGELOG.md
Expand Up @@ -134,8 +134,6 @@ CHANGELOG
FormEvents::BIND_NORM_DATA
* [BC BREAK] reversed the order of the first two arguments to `createNamed`
and `createNamedBuilder` in `FormFactoryInterface`
* [BC BREAK] adapted methods of FormView to match the naming used in
FormInterface and FormBuilder
* deprecated `getChildren` in Form and FormBuilder in favor of `all`
* deprecated `hasChildren` in Form and FormBuilder in favor of `count`
* FormBuilder now implements \IteratorAggregate
Expand Down Expand Up @@ -179,3 +177,4 @@ CHANGELOG
* `isChoiceGroup`
* `isChoiceSelected`
* added method `block` to FormHelper and deprecated `renderBlock` instead
* made FormView properties public and deprecated their accessor methods
103 changes: 103 additions & 0 deletions src/Symfony/Component/Form/FormView.php
Expand Up @@ -67,6 +67,64 @@ public function getName()
return $this->vars['name'];
}

/**
* @param string $name
* @param mixed $value
*
* @return FormView The current view
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Access
* the public property {@link vars} instead.
*/
public function set($name, $value)
{
$this->vars[$name] = $value;

return $this;
}

/**
* @param $name
*
* @return Boolean
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Access
* the public property {@link vars} instead.
*/
public function has($name)
{
return array_key_exists($name, $this->vars);
}

/**
* @param $name
* @param $default
*
* @return mixed
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Access
* the public property {@link vars} instead.
*/
public function get($name, $default = null)
{
if (false === $this->has($name)) {
return $default;
}

return $this->vars[$name];
}

/**
* @return array
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Access
* the public property {@link vars} instead.
*/
public function all()
{
return $this->vars;
}

/**
* Returns the values of all view variables.
*
Expand Down Expand Up @@ -180,6 +238,51 @@ public function hasParent()
return null !== $this->parent;
}

/**
* Sets the children view.
*
* @param array $children The children as instances of FormView
*
* @return FormView The current view
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Access
* the public property {@link children} instead.
*/
public function setChildren(array $children)
{
$this->children = $children;

return $this;
}

/**
* Returns the children.
*
* @return array The children as instances of FormView
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Access
* the public property {@link children} instead.
*/
public function getChildren()
{
return $this->children;
}

/**
* Returns a given child.
*
* @param string $name The name of the child
*
* @return FormView The child view
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Access
* the public property {@link children} instead.
*/
public function getChild($name)
{
return $this->children[$name];
}

/**
* Returns whether this view has any children.
*
Expand Down

0 comments on commit 310f985

Please sign in to comment.