for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Black\Common\Application\Form\Extension;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\PropertyAccess\PropertyAccess;
/**
* Class ImageTypeExtension
*
* This extension add image option for create a preview near the upload form type
*/
class ImageTypeExtension extends AbstractTypeExtension
{
* {@inheritdoc}
public function buildView(FormView $view, FormInterface $form, array $options)
$view->vars['image_url'] = null;
if (array_key_exists('image_path', $options)) {
$parentData = $form->getParent()->getData();
if (null !== $parentData) {
$accessor = PropertyAccess::createPropertyAccessor();
$imageUrl = $accessor->getValue($parentData, $options['image_path']);
} else {
$imageUrl = null;
}
$view->vars['image_url'] = $imageUrl;
public function getExtendedType()
return 'file';
public function configureOptions(OptionsResolver $resolver)
$resolver->setDefined(['image_path']);