diff --git a/cookbook/form/create_form_type_extension.rst b/cookbook/form/create_form_type_extension.rst index 116992d1280..5de981105b9 100644 --- a/cookbook/form/create_form_type_extension.rst +++ b/cookbook/form/create_form_type_extension.rst @@ -104,20 +104,20 @@ tag: services: acme_demo_bundle.image_type_extension: - class: Acme\DemoBundle\Form\Type\ImageTypeExtension + class: Acme\DemoBundle\Form\Extension\ImageTypeExtension tags: - { name: form.type_extension, alias: file } .. code-block:: xml - + .. code-block:: php $container - ->register('acme_demo_bundle.image_type_extension', 'Acme\DemoBundle\Form\Type\ImageTypeExtension') + ->register('acme_demo_bundle.image_type_extension', 'Acme\DemoBundle\Form\Extension\ImageTypeExtension') ->addTag('form.type_extension', array('alias' => 'file')); The ``alias`` key of the tag is the type of field that this extension should @@ -186,7 +186,6 @@ it in the view:: namespace Acme\DemoBundle\Form\Extension; use Symfony\Component\Form\AbstractTypeExtension; - use Symfony\Component\Form\FormBuilder; use Symfony\Component\Form\FormView; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\Util\PropertyPath; @@ -219,16 +218,22 @@ it in the view:: * * @param \Symfony\Component\Form\FormView $view * @param \Symfony\Component\Form\FormInterface $form + * @param array $options */ - public function buildView(FormView $view, FormInterface $form) + public function buildView(FormView $view, FormInterface $form, array $options) { if (array_key_exists('image_path', $options)) { $parentData = $form->getParent()->getData(); - $propertyPath = new PropertyPath($options['image_path']); - $imageUrl = $propertyPath->getValue($parentData); + if (null !== $parentData) { + $propertyPath = new PropertyPath($options['image_path']); + $imageUrl = $propertyPath->getValue($parentData); + } else { + $imageUrl = null; + } + // set an "image_url" variable that will be available when rendering this field - $view->set('image_url', $imageUrl); + $view->vars['image_url'] = $imageUrl; } }