How to display the current picture above the upload field in SonataAdminBundle?

后端 未结 7 2054
广开言路
广开言路 2021-02-01 20:31

I am using SonataAdminBundle (with Doctrine2 ORM) and I have successfully added a file upload feature to my Picture model.

I would like, on the

7条回答
  •  终归单人心
    2021-02-01 20:56

    You can simple do by this way

        $image = $this->getSubject();
        $imageSmall = '';
    
        if($image){
            $container = $this->getConfigurationPool()->getContainer();
            $media = $container->get('sonata.media.twig.extension');
            $format = 'small';
            if($webPath = $image->getImageSmall()){
                $imageSmall = '';
            }
        }
    
       $formMapper->add('imageSmall', 'sonata_media_type', array(
          'provider' => 'sonata.media.provider.image',
          'context' => 'default',
          'help' => $imageSmall
       ));
    

提交回复
热议问题