1
votes

I am using the Symfony CMF Media Bundle to achieve the following. I am having several nodes that can have an image and a downloadable PDF. I have already figured out that the setImage method has to be implemented like that:

public function setPreviewImage($previewImage)
{
    if ($previewImage === null) {
        return $this;
    }

    if (!$previewImage instanceof ImageInterface && !$previewImage instanceof UploadedFile) {
        $type = is_object($previewImage) ? get_class($previewImage) : gettype($previewImage);
        throw new \InvalidArgumentException(sprintf(
            'Image is not a valid type, "%s" given.',
            $type
        ));
    }

    if ($this->previewImage) {
        $this->previewImage->copyContentFromFile($previewImage);
    } elseif ($previewImage instanceof ImageInterface) {
        $previewImage->setName('previewImage');
        $this->previewImage = $previewImage;
    } else {
        $this->previewImage = new Image();
        $this->previewImage->copyContentFromFile($previewImage);
    }

    return $this;
}

Then in another forum someone was suggested to make this property cascade-persistent. with that hint: https://github.com/symfony-cmf/BlockBundle/blob/master/Resources/config/doctrine-phpcr/ImagineBlock.phpcr.xml#L22. Now i am wondering how and were i can set this option in my configuration.

The next part i am wondering about is the cmf_media_file type. Has anyone out here ever managed to store a PDF into a PHPCR node property?

For any help i would be really thankful.

1
Ok figured it out. For anyone using Annotations you have to set it up like this: /** * @var Image * @PHPCR\Child(cascade="persist") */user3676604
Please put your own solution as an answer and mark it as accepted!Etienne Noël
posted the answer but i can mark it as accepted in two days :)user3676604

1 Answers

3
votes

I figured it out by myself. For anyone who is using annotations you have to set it up like this:

use Symfony\Cmf\Bundle\MediaBundle\Doctrine\Phpcr\Image;
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR;

/** 
 * @var Image
 * @PHPCR\Child(cascade="persist")
 */