1

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.

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

1 Answers1

3

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")
 */
  • if the documentation is not clear about this, please open a pull request to fix it. https://github.com/symfony-cmf/symfony-cmf-docs – dbu Sep 29 '15 at 15:51