|
84 | 84 | {{ error.message }} |
85 | 85 | ``` |
86 | 86 |
|
| 87 | + * FormType, ModelType and PropertyPathMapper now have constructors. If you |
| 88 | + extended these classes, you should call the parent constructor now. |
| 89 | + Note that you are not recommended to extend FormType nor ModelType. You should |
| 90 | + extend AbstractType instead and use the Form component's own inheritance |
| 91 | + mechanism (`AbstractType::getParent()`). |
| 92 | + |
| 93 | + Before: |
| 94 | + |
| 95 | + ``` |
| 96 | + use Symfony\Component\Form\Extensions\Core\DataMapper\PropertyPathMapper; |
| 97 | +
|
| 98 | + class CustomMapper extends PropertyPathMapper |
| 99 | + { |
| 100 | + public function __construct() |
| 101 | + { |
| 102 | + // ... |
| 103 | + } |
| 104 | +
|
| 105 | + // ... |
| 106 | + } |
| 107 | + ``` |
| 108 | + |
| 109 | + After: |
| 110 | + |
| 111 | + ``` |
| 112 | + use Symfony\Component\Form\Extensions\Core\DataMapper\PropertyPathMapper; |
| 113 | +
|
| 114 | + class CustomMapper extends PropertyPathMapper |
| 115 | + { |
| 116 | + public function __construct() |
| 117 | + { |
| 118 | + parent::__construct(); |
| 119 | +
|
| 120 | + // ... |
| 121 | + } |
| 122 | +
|
| 123 | + // ... |
| 124 | + } |
| 125 | + ``` |
| 126 | + |
87 | 127 | #### Deprecations |
88 | 128 |
|
89 | 129 | * The methods `getParent()`, `setParent()` and `hasParent()` in |
90 | 130 | `FormBuilderInterface` were deprecated and will be removed in Symfony 2.3. |
91 | 131 | You should not rely on these methods in your form type because the parent |
92 | 132 | of a form can change after building it. |
93 | 133 |
|
| 134 | + * The class PropertyPath and related classes were deprecated and moved to a |
| 135 | + dedicated component PropertyAccess. If you used any of these classes or |
| 136 | + interfaces, you should adapt the namespaces now. During the move, |
| 137 | + InvalidPropertyException was renamed to NoSuchPropertyException. |
| 138 | + |
| 139 | + Before: |
| 140 | + |
| 141 | + ``` |
| 142 | + use Symfony\Component\Form\Util\PropertyPath; |
| 143 | + use Symfony\Component\Form\Util\PropertyPathBuilder; |
| 144 | + use Symfony\Component\Form\Util\PropertyPathInterface; |
| 145 | + use Symfony\Component\Form\Util\PropertyPathIterator; |
| 146 | + use Symfony\Component\Form\Util\PropertyPathIteratorInterface; |
| 147 | + use Symfony\Component\Form\Exception\InvalidPropertyException; |
| 148 | + use Symfony\Component\Form\Exception\InvalidPropertyPathException; |
| 149 | + use Symfony\Component\Form\Exception\PropertyAccessDeniedException; |
| 150 | + ``` |
| 151 | + |
| 152 | + After: |
| 153 | + |
| 154 | + ``` |
| 155 | + use Symfony\Component\PropertyAccess\PropertyPath; |
| 156 | + use Symfony\Component\PropertyAccess\PropertyPathBuilder; |
| 157 | + use Symfony\Component\PropertyAccess\PropertyPathInterface; |
| 158 | + use Symfony\Component\PropertyAccess\PropertyPathIterator; |
| 159 | + use Symfony\Component\PropertyAccess\PropertyPathIteratorInterface; |
| 160 | + use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException; |
| 161 | + use Symfony\Component\PropertyAccess\Exception\InvalidPropertyPathException; |
| 162 | + use Symfony\Component\PropertyAccess\Exception\PropertyAccessDeniedException; |
| 163 | + ``` |
| 164 | + |
| 165 | + Also, `FormUtil::singularify()` was split away into a class StringUtil |
| 166 | + in the new component. |
| 167 | + |
| 168 | + Before: |
| 169 | + |
| 170 | + ``` |
| 171 | + use Symfony\Component\Form\Util\FormUtil; |
| 172 | +
|
| 173 | + $singular = FormUtil::singularify($plural); |
| 174 | + ``` |
| 175 | + |
| 176 | + After: |
| 177 | + |
| 178 | + ``` |
| 179 | + use Symfony\Component\PropertyAccess\StringUtil; |
| 180 | +
|
| 181 | + $singular = StringUtil::singularify($plural); |
| 182 | + ``` |
| 183 | + |
| 184 | + The methods `getValue()` and `setValue()` were moved to a new class |
| 185 | + PropertyAccessor. |
| 186 | + |
| 187 | + Before: |
| 188 | + |
| 189 | + ``` |
| 190 | + use Symfony\Component\Form\Util\PropertyPath; |
| 191 | +
|
| 192 | + $propertyPath = new PropertyPath('some.path'); |
| 193 | +
|
| 194 | + $value = $propertyPath->getValue($object); |
| 195 | + $propertyPath->setValue($object, 'new value'); |
| 196 | + ``` |
| 197 | + |
| 198 | + After (alternative 1): |
| 199 | + |
| 200 | + ``` |
| 201 | + use Symfony\Component\PropertyAccess\PropertyAccess; |
| 202 | +
|
| 203 | + $accessor = PropertyAccess::getPropertyAccessor(); |
| 204 | +
|
| 205 | + $value = $propertyAccessor->getValue($object, 'some.path'); |
| 206 | + $accessor->setValue($object, 'some.path', 'new value'); |
| 207 | + ``` |
| 208 | + |
| 209 | + After (alternative 2): |
| 210 | + |
| 211 | + ``` |
| 212 | + use Symfony\Component\PropertyAccess\PropertyAccess; |
| 213 | + use Symfony\Component\PropertyAccess\PropertyPath; |
| 214 | +
|
| 215 | + $accessor = PropertyAccess::getPropertyAccessor(); |
| 216 | + $propertyPath = new PropertyPath('some.path'); |
| 217 | +
|
| 218 | + $value = $propertyAccessor->getValue($object, $propertyPath); |
| 219 | + $accessor->setValue($object, $propertyPath, 'new value'); |
| 220 | + ``` |
| 221 | + |
94 | 222 | ### Routing |
95 | 223 |
|
96 | 224 | * RouteCollection does not behave like a tree structure anymore but as a flat |
|
0 commit comments