Skip to content

Commit

Permalink
Merge pull request #131 from antonioperic/page-image
Browse files Browse the repository at this point in the history
added image for blog fixtures
  • Loading branch information
bitbager authored Apr 25, 2018
2 parents b67ce6d + ef090a5 commit 38390a1
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/Fixture/BlockFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@

use BitBag\SyliusCmsPlugin\Fixture\Factory\FixtureFactoryInterface;
use Sylius\Bundle\FixturesBundle\Fixture\AbstractFixture;
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;

final class BlockFixture extends AbstractFixture implements FixtureInterface
final class BlockFixture extends AbstractFixture
{
/**
* @var FixtureFactoryInterface
Expand Down
22 changes: 22 additions & 0 deletions src/Fixture/Factory/PageFixtureFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@

namespace BitBag\SyliusCmsPlugin\Fixture\Factory;

use BitBag\SyliusCmsPlugin\Entity\PageImage;
use BitBag\SyliusCmsPlugin\Entity\PageInterface;
use BitBag\SyliusCmsPlugin\Entity\PageTranslationInterface;
use BitBag\SyliusCmsPlugin\Entity\SectionInterface;
use BitBag\SyliusCmsPlugin\Repository\PageRepositoryInterface;
use BitBag\SyliusCmsPlugin\Repository\SectionRepositoryInterface;
use Sylius\Component\Channel\Context\ChannelContextInterface;
use Sylius\Component\Core\Repository\ProductRepositoryInterface;
use Sylius\Component\Core\Uploader\ImageUploaderInterface;
use Sylius\Component\Locale\Context\LocaleContextInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;

final class PageFixtureFactory implements FixtureFactoryInterface
{
Expand All @@ -44,6 +47,11 @@ final class PageFixtureFactory implements FixtureFactoryInterface
*/
private $sectionRepository;

/**
* @var ImageUploaderInterface
*/
private $imageUploader;

/**
* @var ProductRepositoryInterface
*/
Expand All @@ -65,6 +73,7 @@ final class PageFixtureFactory implements FixtureFactoryInterface
* @param PageRepositoryInterface $pageRepository
* @param ProductRepositoryInterface $productRepository
* @param SectionRepositoryInterface $sectionRepository
* @param ImageUploaderInterface $imageUploader
* @param ChannelContextInterface $channelContext
* @param LocaleContextInterface $localeContext
*/
Expand All @@ -73,6 +82,7 @@ public function __construct(
FactoryInterface $pageTranslationFactory,
PageRepositoryInterface $pageRepository,
SectionRepositoryInterface $sectionRepository,
ImageUploaderInterface $imageUploader,
ProductRepositoryInterface $productRepository,
ChannelContextInterface $channelContext,
LocaleContextInterface $localeContext
Expand All @@ -81,6 +91,7 @@ public function __construct(
$this->pageTranslationFactory = $pageTranslationFactory;
$this->pageRepository = $pageRepository;
$this->sectionRepository = $sectionRepository;
$this->imageUploader = $imageUploader;
$this->productRepository = $productRepository;
$this->channelContext = $channelContext;
$this->localeContext = $localeContext;
Expand Down Expand Up @@ -141,6 +152,17 @@ private function createPage(string $code, array $pageData, bool $generateSlug =
$pageTranslation->setMetaDescription($translation['meta_description']);
$pageTranslation->setContent($translation['content']);

if ($translation['image_path']) {
$image = new PageImage();
$path = $translation['image_path'];
$uploadedImage = new UploadedFile($path, md5($path).'.jpg');

$image->setFile($uploadedImage);
$pageTranslation->setImage($image);

$this->imageUploader->upload($image);
}

$page->addTranslation($pageTranslation);
}

Expand Down
3 changes: 1 addition & 2 deletions src/Fixture/FrequentlyAskedQuestionFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@

use BitBag\SyliusCmsPlugin\Fixture\Factory\FixtureFactoryInterface;
use Sylius\Bundle\FixturesBundle\Fixture\AbstractFixture;
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;

final class FrequentlyAskedQuestionFixture extends AbstractFixture implements FixtureInterface
final class FrequentlyAskedQuestionFixture extends AbstractFixture
{
/**
* @var FixtureFactoryInterface
Expand Down
4 changes: 2 additions & 2 deletions src/Fixture/PageFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@

use BitBag\SyliusCmsPlugin\Fixture\Factory\FixtureFactoryInterface;
use Sylius\Bundle\FixturesBundle\Fixture\AbstractFixture;
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;

final class PageFixture extends AbstractFixture implements FixtureInterface
final class PageFixture extends AbstractFixture
{
/**
* @var FixtureFactoryInterface
Expand Down Expand Up @@ -70,6 +69,7 @@ protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void
->children()
->scalarNode('slug')->defaultNull()->end()
->scalarNode('name')->defaultNull()->end()
->scalarNode('image_path')->defaultNull()->end()
->scalarNode('meta_keywords')->defaultNull()->end()
->scalarNode('meta_description')->defaultNull()->end()
->scalarNode('content')->defaultNull()->end()
Expand Down
3 changes: 1 addition & 2 deletions src/Fixture/SectionFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@

use BitBag\SyliusCmsPlugin\Fixture\Factory\FixtureFactoryInterface;
use Sylius\Bundle\FixturesBundle\Fixture\AbstractFixture;
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;

final class SectionFixture extends AbstractFixture implements FixtureInterface
final class SectionFixture extends AbstractFixture
{
/**
* @var FixtureFactoryInterface
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/services/fixture.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ services:
- "@bitbag_sylius_cms_plugin.factory.page_translation"
- "@bitbag_sylius_cms_plugin.repository.page"
- "@bitbag_sylius_cms_plugin.repository.section"
- "@sylius.image_uploader"
- "@sylius.repository.product"
- "@sylius.context.channel"
- "@sylius.context.locale"
Expand Down
1 change: 1 addition & 0 deletions tests/Application/app/config/fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ sylius_fixtures:
translations:
en_US:
name: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Verba tu fingas et ea dicas, quae non sentias?"
image_path: "%fixtures_dir%/homepage_header.jpeg"
content: |
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Verba tu fingas et ea dicas, quae non sentias? Fortitudinis quaedam praecepta sunt ac paene leges, quae effeminari virum vetant in dolore. Propter nos enim illam, non propter eam nosmet ipsos diligimus. At ego quem huic anteponam non audeo dicere; </p>
Expand Down

0 comments on commit 38390a1

Please sign in to comment.