예제 #1
0
 public function load(ObjectManager $manager)
 {
     NodeHelper::createPath($manager->getPhpcrSession(), '/test');
     $testDataDir = realpath(__DIR__ . '/../../app/Resources/data');
     $root = $manager->find(null, '/test');
     // media root
     $mediaRoot = new Generic();
     $mediaRoot->setNodename('media');
     $mediaRoot->setParent($root);
     $manager->persist($mediaRoot);
     // content root
     $contentRoot = new Generic();
     $contentRoot->setNodename('content');
     $contentRoot->setParent($root);
     $manager->persist($contentRoot);
     // File
     $file = new File();
     $file->setParent($mediaRoot);
     $file->setName('file-1.txt');
     $file->setContentFromString('Test file 1.');
     $file->setContentType('text/plain');
     $manager->persist($file);
     // Image
     $image = new Image();
     $image->setParent($mediaRoot);
     $image->setName('cmf-logo.png');
     $image->setFileContentFromFilesystem($testDataDir . '/cmf-logo.png');
     $manager->persist($image);
     $image2 = new Image();
     $image2->setParent($contentRoot);
     $image2->setName('cmf-logo-2.png');
     $image2->setFileContentFromFilesystem($testDataDir . '/cmf-logo.png');
     $manager->persist($image2);
     // Content with image
     $content = new Content();
     $content->setParent($contentRoot);
     $content->setName('content-with-image');
     $content->setTitle('Content document with image embedded');
     $contentImage = new Image();
     $contentImage->setFileContentFromFilesystem($testDataDir . '/cmf-logo.png');
     $content->setFile($contentImage);
     $manager->persist($content);
     // Content with file
     $content2 = new Content();
     $content2->setParent($contentRoot);
     $content2->setName('content-with-file');
     $content2->setTitle('Content document with file attached');
     $contentFile = new File();
     $contentFile->setFileContentFromFilesystem($testDataDir . '/testfile.txt');
     $content2->setFile($contentFile);
     $manager->persist($content2);
     $manager->flush();
 }
예제 #2
0
 /**
  * @param null $imageTwo
  *
  * @return $this
  */
 public function setImageTwo($imageTwo = null)
 {
     if (!$imageTwo) {
         return $this;
     }
     if (!$imageTwo instanceof ImageInterface && !$imageTwo instanceof UploadedFile) {
         $type = is_object($imageTwo) ? get_class($imageTwo) : gettype($imageTwo);
         throw new \InvalidArgumentException(sprintf('Image is not a valid type, "%s" given.', $type));
     }
     if ($this->imageTwo) {
         // existing image, only update content
         $this->imageTwo->copyContentFromFile($imageTwo);
     } elseif ($imageTwo instanceof ImageInterface) {
         $imageTwo->setName('image');
         // ensure document has right name
         $this->imageTwo = $imageTwo;
     } else {
         $this->imageTwo = new Image();
         $this->imageTwo->copyContentFromFile($imageTwo);
     }
     return $this;
 }
예제 #3
0
 /**
  * Set the image for this block.
  *
  * Setting null will do nothing, as this is what happens when you edit this
  * block in a form without uploading a replacement file.
  *
  * If you need to delete the Image, you can use getImage and delete it with
  * the document manager. Note that this block does not make much sense
  * without an image, though.
  *
  * @param ImageInterface|UploadedFile|null $image optional the image to update
  *
  * @return $this
  *
  * @throws \InvalidArgumentException If the $image parameter can not be handled.
  */
 public function setImage($image = null)
 {
     if (!$image) {
         return $this;
     }
     if (!$image instanceof ImageInterface && !$image instanceof UploadedFile) {
         $type = is_object($image) ? get_class($image) : gettype($image);
         throw new \InvalidArgumentException(sprintf('Image is not a valid type, "%s" given.', $type));
     }
     if ($this->image) {
         // existing image, only update content
         // TODO: https://github.com/doctrine/phpcr-odm/pull/262
         $this->image->copyContentFromFile($image);
     } elseif ($image instanceof ImageInterface) {
         $image->setName('image');
         // ensure document has right name
         $this->image = $image;
     } else {
         $this->image = new Image();
         $this->image->copyContentFromFile($image);
     }
     return $this;
 }