Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function createImageRendition(ImageInterface $image, ArticleMediaInterface $articleMedia, string $key, Rendition $rendition) : ImageRenditionInterface
 {
     $imageRendition = new ImageRendition();
     $imageRendition->setImage($image);
     $imageRendition->setMedia($articleMedia);
     $imageRendition->setHeight($rendition->getHeight());
     $imageRendition->setWidth($rendition->getWidth());
     $imageRendition->setName($key);
     return $imageRendition;
 }
 /**
  * Sets articles manually (not via Alice) for test env due to fatal error:
  * Method PHPCRProxies\__CG__\Doctrine\ODM\PHPCR\Document\Generic::__toString() must not throw an exception.
  */
 public function loadArticles($env, $manager)
 {
     $articles = ['test' => [['title' => 'Test news article', 'content' => 'Test news article content', 'locale' => 'en']]];
     $renditions = ['original' => ['width' => '4000', 'height' => '2667', 'media' => '12345678987654321a'], '16-9' => ['width' => '1079', 'height' => '720', 'media' => '12345678987654321b'], '4-3' => ['width' => '800', 'height' => '533', 'media' => '12345678987654321c']];
     $mediaManager = $this->container->get('swp_content_bundle.manager.media');
     $fakeImage = __DIR__ . '/../../Resources/assets/test_cc_image.jpg';
     if (isset($articles[$env])) {
         foreach ($articles[$env] as $articleData) {
             $article = $this->container->get('swp.factory.article')->create();
             $article->setTitle($articleData['title']);
             $article->setBody($articleData['content']);
             $article->setLocale($articleData['locale']);
             $article->setPublishedAt(new \DateTime());
             $article->setPublishable(true);
             $article->setStatus(ArticleInterface::STATUS_PUBLISHED);
             $manager->persist($article);
             // create Media
             $articleMediaClass = $this->container->getParameter('swp.model.media.class');
             $articleMedia = new $articleMediaClass();
             $articleMedia->setArticle($article);
             $articleMedia->setKey('embedded6358005131');
             $articleMedia->setBody('article media body');
             $articleMedia->setByLine('By Best Editor');
             $articleMedia->setLocated('Porto');
             $articleMedia->setDescription('Media description');
             $articleMedia->setUsageTerms('Some super open terms');
             $articleMedia->setMimetype('image/jpeg');
             $manager->persist($articleMedia);
             /* @var $rendition Rendition */
             foreach ($renditions as $key => $rendition) {
                 $uploadedFile = new UploadedFile($fakeImage, $rendition['media'], 'image/jpeg', filesize($fakeImage), null, true);
                 $image = $mediaManager->handleUploadedFile($uploadedFile, $rendition['media']);
                 if ($key === 'original') {
                     $articleMedia->setImage($image);
                 }
                 $imageRendition = new ImageRendition();
                 $imageRendition->setImage($image);
                 $imageRendition->setHeight($rendition['height']);
                 $imageRendition->setWidth($rendition['width']);
                 $imageRendition->setName($key);
                 $imageRendition->setMedia($articleMedia);
                 $articleMedia->addRendition($imageRendition);
                 $manager->persist($imageRendition);
             }
         }
         $manager->flush();
     }
 }