symfonysonata-media-bundle

SonataMediaBundle Type error when trying to delete the link with media


i have project that uses sonataAdmin and sonataMedia when i tried to delete the image using the check box provided by the bundle click to see image

i get this error :

Type error: Argument 1 passed to BackBundle\Entity\reference::setMedia() must implement interface Sonata\MediaBundle\Model\MediaInterface, null given, called in /home/hichem/PhpstormProjects/sifastProject/vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php on line 591

it appears exactly here:

Stack Trace

in src/BackBundle/Entity/reference.php at line 69  -
        /**
         * @param MediaInterface $media
         */
        public function setMedia(MediaInterface $media)
        {
            $this->media = $media;
        }

from what i've understand(or at least think so)the setter can't set the value with null if any one know what's the problem please help


Solution

  • Because you have no selected file I think that this will help you:

    /**
     * @param MediaInterface $media
     */
    public function setMedia(MediaInterface $media = null)
    {
        $this->media = $media;
    }