Skip to content

Commit 58f1aa2

Browse files
committed
[#1905] Backporting some changes to 2.0
1 parent f02a453 commit 58f1aa2

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

cookbook/form/create_form_type_extension.rst

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,20 @@ tag:
106106
107107
services:
108108
acme_demo_bundle.image_type_extension:
109-
class: Acme\DemoBundle\Form\Type\ImageTypeExtension
109+
class: Acme\DemoBundle\Form\Extension\ImageTypeExtension
110110
tags:
111111
- { name: form.type_extension, alias: file }
112112
113113
.. code-block:: xml
114114
115-
<service id="acme_demo_bundle.image_type_extension" class="Acme\DemoBundle\Form\Type\ImageTypeExtension">
115+
<service id="acme_demo_bundle.image_type_extension" class="Acme\DemoBundle\Form\Extension\ImageTypeExtension">
116116
<tag name="form.type_extension" alias="file" />
117117
</service>
118118
119119
.. code-block:: php
120120
121121
$container
122-
->register('acme_demo_bundle.image_type_extension', 'Acme\DemoBundle\Form\Type\ImageTypeExtension')
122+
->register('acme_demo_bundle.image_type_extension', 'Acme\DemoBundle\Form\Extension\ImageTypeExtension')
123123
->addTag('form.type_extension', array('alias' => 'file'));
124124
125125
The ``alias`` key of the tag is the type of field that this extension should
@@ -239,10 +239,14 @@ it in the view::
239239
if ($form->hasAttribute('image_path')) {
240240
$parentData = $form->getParent()->getData();
241241

242-
$propertyPath = new PropertyPath($form->getAttribute('image_path'));
243-
$imageUrl = $propertyPath->getValue($parentData);
242+
if (null != $parentData) {
243+
$propertyPath = new PropertyPath($form->getAttribute('image_path'));
244+
$imageUrl = $propertyPath->getValue($parentData);
245+
} else {
246+
$imageUrl = null;
247+
}
244248
// set an "image_url" variable that will be available when rendering this field
245-
$view->set('image_url', $imageUrl);
249+
$view->vars['image_url'] = $imageUrl;
246250
}
247251
}
248252

0 commit comments

Comments
 (0)