Form/Type/UploadType.php
public function buildForm(FormBuilderInterface $builder, array $options)
    {
        if ($options['js_upload']) {
            $builder->add('key', 'hidden');
        }

        if ($options['rename_field']) {
            $builder->add('rename', 'text', [
                'label' => 'ekyna_core.field.rename',
                'required' => $options['required'],
                'sizing' => 'sm',
                'admin_helper' => 'FILE_RENAME',
                'attr' => [
                    'class' => 'file-rename',
                    'label_col' => 2,
                    'widget_col' => 10
                ],
            ]);
        }

        $builder->addEventListener(
            FormEvents::PRE_SET_DATA,
            function(FormEvent $event) use ($options) {
                $form = $event->getForm();
                /** @var \Ekyna\Bundle\CoreBundle\Model\UploadableInterface $uploadable */
                $uploadable = $event->getData();

                if (null !== $uploadable && null !== $uploadable->getPath()) {
                    $form->add('file', 'file', [
                        'label' => 'ekyna_core.field.file',
                        'required' => false,
                        'sizing' => 'sm',
                        'admin_helper' => 'FILE_UPLOAD',
                        'attr' => [
                            'label_col' => 2,
                            'widget_col' => 10
                        ]
                    ]);
                    if ($options['unlink_field']) {
                        $form->add('unlink', 'checkbox', [
                            'label' => 'ekyna_core.field.unlink',
                            'required' => false,
                            'sizing' => 'sm',
                            'admin_helper' => 'FILE_UNLINK',
                            'attr' => [
                                'label_col' => 2,
                                'widget_col' => 10,
                                'align_with_widget' => true,
                            ]
                        ]);
                    }
                } else {
                    $form->add('file', 'file', [
                        'label' => 'ekyna_core.field.file',
                        'required' => true,
                        'sizing' => 'sm',
                        'admin_helper' => 'FILE_UPLOAD',
                        'attr' => [
                            'label_col' => 2,
                            'widget_col' => 10
                        ]
                    ]);
                }
            }
        );

        $builder->addModelTransformer(new UploadableToNullTransformer());
    }
public function buildForm(FormBuilderInterface $builder, array $options)
    {
        if ($options['js_upload']) {
            $builder->add('key', 'hidden');
        }

        if ($options['rename_field']) {
            $builder->add('rename', 'text', [
                'label' => 'ekyna_core.field.rename',
                'required' => $options['required'],
                'sizing' => 'sm',
                'admin_helper' => 'FILE_RENAME',
                'attr' => [
                    'class' => 'file-rename',
                    'label_col' => 2,
                    'widget_col' => 10
                ],
            ]);
        }

        $builder->addEventListener(
            FormEvents::PRE_SET_DATA,
            function(FormEvent $event) use ($options) {
                $form = $event->getForm();
                /** @var \Ekyna\Bundle\CoreBundle\Model\UploadableInterface $uploadable */
                $uploadable = $event->getData();

                if (null !== $uploadable && null !== $uploadable->getPath()) {
                    $form->add('file', 'file', [
                        'label' => 'ekyna_core.field.file',
                        'required' => false,
                        'sizing' => 'sm',
                        'admin_helper' => 'FILE_UPLOAD',
                        'attr' => [
                            'label_col' => 2,
                            'widget_col' => 10
                        ]
                    ]);
                    if ($options['unlink_field']) {
                        $form->add('unlink', 'checkbox', [
                            'label' => 'ekyna_core.field.unlink',
                            'required' => false,
                            'sizing' => 'sm',
                            'admin_helper' => 'FILE_UNLINK',
                            'attr' => [
                                'label_col' => 2,
                                'widget_col' => 10,
                                'align_with_widget' => true,
                            ]
                        ]);
                    }
                } else {
                    $form->add('file', 'file', [
                        'label' => 'ekyna_core.field.file',
                        'required' => true,
                        'sizing' => 'sm',
                        'admin_helper' => 'FILE_UPLOAD',
                        'attr' => [
                            'label_col' => 2,
                            'widget_col' => 10
                        ]
                    ]);
                }
            }
        );

        $builder->addModelTransformer(new UploadableToNullTransformer());
    }
{@inheritdoc}