From 6216b11d0bcce70b1e8ea0bfa6403c5d9da4c5d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Kr=C3=B3l?= Date: Sun, 15 Jul 2018 16:52:46 +0200 Subject: [PATCH 1/6] Prepare 2.0.0 release --- spec/Entity/PageSpec.php | 4 ++-- spec/EventListener/PageImageUploadListenerSpec.php | 6 +++--- spec/Resolver/PageResourceResolverSpec.php | 4 ++-- .../Twig/Extension/RenderProductPagesExtensionSpec.php | 4 ++-- src/Controller/PageController.php | 4 ++-- src/Entity/Page.php | 2 +- .../{PageContentInterface.php => PageInterface.php} | 2 +- src/EventListener/PageImageUploadListener.php | 4 ++-- src/Fixture/Factory/PageFixtureFactory.php | 8 ++++---- src/Importer/PageImporter.php | 6 +++--- src/Repository/PageRepository.php | 6 +++--- src/Repository/PageRepositoryInterface.php | 6 +++--- src/Resolver/PageResourceResolver.php | 6 +++--- src/Resolver/PageResourceResolverInterface.php | 4 ++-- src/SitemapProvider/PageUrlProvider.php | 10 +++++----- src/Twig/Extension/RenderProductPagesExtension.php | 4 ++-- tests/Behat/Context/Setup/PageContext.php | 10 +++++----- 17 files changed, 45 insertions(+), 45 deletions(-) rename src/Entity/{PageContentInterface.php => PageInterface.php} (97%) diff --git a/spec/Entity/PageSpec.php b/spec/Entity/PageSpec.php index 8cb5060c9..a59b8214d 100755 --- a/spec/Entity/PageSpec.php +++ b/spec/Entity/PageSpec.php @@ -13,7 +13,7 @@ namespace spec\BitBag\SyliusCmsPlugin\Entity; use BitBag\SyliusCmsPlugin\Entity\Page; -use BitBag\SyliusCmsPlugin\Entity\PageContentInterface; +use BitBag\SyliusCmsPlugin\Entity\PageInterface; use BitBag\SyliusCmsPlugin\Entity\SectionInterface; use PhpSpec\ObjectBehavior; use Sylius\Component\Core\Model\ChannelInterface; @@ -34,7 +34,7 @@ function it_is_a_resource(): void function it_implements_page_interface(): void { - $this->shouldHaveType(PageContentInterface::class); + $this->shouldHaveType(PageInterface::class); } function it_allows_access_via_properties(): void diff --git a/spec/EventListener/PageImageUploadListenerSpec.php b/spec/EventListener/PageImageUploadListenerSpec.php index 493d39292..8329339b1 100755 --- a/spec/EventListener/PageImageUploadListenerSpec.php +++ b/spec/EventListener/PageImageUploadListenerSpec.php @@ -13,7 +13,7 @@ namespace spec\BitBag\SyliusCmsPlugin\EventListener; use BitBag\SyliusCmsPlugin\Entity\PageImageInterface; -use BitBag\SyliusCmsPlugin\Entity\PageContentInterface; +use BitBag\SyliusCmsPlugin\Entity\PageInterface; use BitBag\SyliusCmsPlugin\Entity\PageTranslationInterface; use BitBag\SyliusCmsPlugin\EventListener\PageImageUploadListener; use Doctrine\Common\Collections\ArrayCollection; @@ -36,7 +36,7 @@ function it_is_initializable(): void function it_does_not_upload_if_not_page_instance( ResourceControllerEvent $event, - PageContentInterface $page + PageInterface $page ): void { $event->getSubject()->willReturn(Argument::any()); @@ -45,7 +45,7 @@ function it_does_not_upload_if_not_page_instance( function it_upload_image_for_each_translations( ResourceControllerEvent $event, - PageContentInterface $page, + PageInterface $page, PageTranslationInterface $pageTranslation, PageImageInterface $pageImage, ImageUploaderInterface $pageImageUploader diff --git a/spec/Resolver/PageResourceResolverSpec.php b/spec/Resolver/PageResourceResolverSpec.php index 52f30ffee..acaf688df 100755 --- a/spec/Resolver/PageResourceResolverSpec.php +++ b/spec/Resolver/PageResourceResolverSpec.php @@ -12,7 +12,7 @@ namespace spec\BitBag\SyliusCmsPlugin\Resolver; -use BitBag\SyliusCmsPlugin\Entity\PageContentInterface; +use BitBag\SyliusCmsPlugin\Entity\PageInterface; use BitBag\SyliusCmsPlugin\Repository\PageRepositoryInterface; use BitBag\SyliusCmsPlugin\Resolver\PageResourceResolver; use BitBag\SyliusCmsPlugin\Resolver\PageResourceResolverInterface; @@ -59,7 +59,7 @@ function it_logs_warning_if_page_was_not_found( function it_returns_page_if_found_in_database( PageRepositoryInterface $pageRepository, LocaleContextInterface $localeContext, - PageContentInterface $page + PageInterface $page ) { $localeContext->getLocaleCode()->willReturn('en_US'); $pageRepository->findOneEnabledByCode('homepage_banner', 'en_US')->willReturn($page); diff --git a/spec/Twig/Extension/RenderProductPagesExtensionSpec.php b/spec/Twig/Extension/RenderProductPagesExtensionSpec.php index cdb8a75f7..43fa8dd8e 100755 --- a/spec/Twig/Extension/RenderProductPagesExtensionSpec.php +++ b/spec/Twig/Extension/RenderProductPagesExtensionSpec.php @@ -12,7 +12,7 @@ namespace spec\BitBag\SyliusCmsPlugin\Twig\Extension; -use BitBag\SyliusCmsPlugin\Entity\PageContentInterface; +use BitBag\SyliusCmsPlugin\Entity\PageInterface; use BitBag\SyliusCmsPlugin\Entity\SectionInterface; use BitBag\SyliusCmsPlugin\Repository\PageRepositoryInterface; use BitBag\SyliusCmsPlugin\Twig\Extension\RenderProductPagesExtension; @@ -59,7 +59,7 @@ function it_renders_product_pages( ProductInterface $product, ChannelInterface $channel, PageRepositoryInterface $pageRepository, - PageContentInterface $page, + PageInterface $page, SectionInterface $section, EngineInterface $templatingEngine ): void { diff --git a/src/Controller/PageController.php b/src/Controller/PageController.php index 30fe80e86..9d91900b7 100755 --- a/src/Controller/PageController.php +++ b/src/Controller/PageController.php @@ -12,7 +12,7 @@ namespace BitBag\SyliusCmsPlugin\Controller; -use BitBag\SyliusCmsPlugin\Entity\PageContentInterface; +use BitBag\SyliusCmsPlugin\Entity\PageInterface; use FOS\RestBundle\View\View; use Sylius\Bundle\ResourceBundle\Controller\ResourceController; use Sylius\Component\Resource\ResourceActions; @@ -67,7 +67,7 @@ public function previewAction(Request $request): Response $form->handleRequest($request); - /** @var PageContentInterface $newResource */ + /** @var PageInterface $newResource */ $newResource = $form->getData(); $defaultLocale = $this->getParameter('locale'); diff --git a/src/Entity/Page.php b/src/Entity/Page.php index 19ba0585e..a1d901da8 100755 --- a/src/Entity/Page.php +++ b/src/Entity/Page.php @@ -18,7 +18,7 @@ use Sylius\Component\Resource\Model\TranslatableTrait; use Sylius\Component\Resource\Model\TranslationInterface; -class Page implements PageContentInterface +class Page implements PageInterface { use ToggleableTrait; use ProductsAwareTrait; diff --git a/src/Entity/PageContentInterface.php b/src/Entity/PageInterface.php similarity index 97% rename from src/Entity/PageContentInterface.php rename to src/Entity/PageInterface.php index 0e4c7350c..4741eb7c1 100755 --- a/src/Entity/PageContentInterface.php +++ b/src/Entity/PageInterface.php @@ -18,7 +18,7 @@ use Sylius\Component\Resource\Model\ToggleableInterface; use Sylius\Component\Resource\Model\TranslatableInterface; -interface PageContentInterface extends +interface PageInterface extends ResourceInterface, TranslatableInterface, ToggleableInterface, diff --git a/src/EventListener/PageImageUploadListener.php b/src/EventListener/PageImageUploadListener.php index a668a7eb5..6ed205699 100755 --- a/src/EventListener/PageImageUploadListener.php +++ b/src/EventListener/PageImageUploadListener.php @@ -12,7 +12,7 @@ namespace BitBag\SyliusCmsPlugin\EventListener; -use BitBag\SyliusCmsPlugin\Entity\PageContentInterface; +use BitBag\SyliusCmsPlugin\Entity\PageInterface; use BitBag\SyliusCmsPlugin\Entity\PageTranslationInterface; use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent; use Sylius\Component\Core\Uploader\ImageUploaderInterface; @@ -32,7 +32,7 @@ public function uploadImage(ResourceControllerEvent $event): void { $page = $event->getSubject(); - Assert::isInstanceOf($page, PageContentInterface::class); + Assert::isInstanceOf($page, PageInterface::class); /** @var PageTranslationInterface $translation */ foreach ($page->getTranslations() as $translation) { diff --git a/src/Fixture/Factory/PageFixtureFactory.php b/src/Fixture/Factory/PageFixtureFactory.php index 9b2fa4329..6b96f61ed 100755 --- a/src/Fixture/Factory/PageFixtureFactory.php +++ b/src/Fixture/Factory/PageFixtureFactory.php @@ -12,7 +12,7 @@ namespace BitBag\SyliusCmsPlugin\Fixture\Factory; -use BitBag\SyliusCmsPlugin\Entity\PageContentInterface; +use BitBag\SyliusCmsPlugin\Entity\PageInterface; use BitBag\SyliusCmsPlugin\Entity\PageImage; use BitBag\SyliusCmsPlugin\Entity\PageTranslationInterface; use BitBag\SyliusCmsPlugin\Entity\SectionInterface; @@ -93,7 +93,7 @@ public function load(array $data): void private function createPage(string $code, array $pageData, bool $generateSlug = false): void { - /** @var PageContentInterface $page */ + /** @var PageInterface $page */ $page = $this->pageFactory->createNew(); $products = $pageData['products']; @@ -136,7 +136,7 @@ private function createPage(string $code, array $pageData, bool $generateSlug = $this->pageRepository->add($page); } - private function resolveProducts(PageContentInterface $page, int $limit): void + private function resolveProducts(PageInterface $page, int $limit): void { $products = $this->productRepository->findLatestByChannel( $this->channelContext->getChannel(), @@ -149,7 +149,7 @@ private function resolveProducts(PageContentInterface $page, int $limit): void } } - private function resolveSections(PageContentInterface $page, array $sections): void + private function resolveSections(PageInterface $page, array $sections): void { foreach ($sections as $sectionCode) { /** @var SectionInterface $section */ diff --git a/src/Importer/PageImporter.php b/src/Importer/PageImporter.php index 3c3b79c4a..b38d37927 100644 --- a/src/Importer/PageImporter.php +++ b/src/Importer/PageImporter.php @@ -13,7 +13,7 @@ namespace BitBag\SyliusCmsPlugin\Importer; use BitBag\SyliusCmsPlugin\Downloader\ImageDownloaderInterface; -use BitBag\SyliusCmsPlugin\Entity\PageContentInterface; +use BitBag\SyliusCmsPlugin\Entity\PageInterface; use BitBag\SyliusCmsPlugin\Entity\PageImage; use BitBag\SyliusCmsPlugin\Entity\PageTranslationInterface; use BitBag\SyliusCmsPlugin\Resolver\ImporterChannelsResolverInterface; @@ -86,7 +86,7 @@ public function import(array $row): void $code = $this->getColumnValue(self::CODE_COLUMN, $row); Assert::notNull($code); - /** @var PageContentInterface $page */ + /** @var PageInterface $page */ $page = $this->pageResourceResolver->getResource($code); $page->setCode($code); @@ -125,7 +125,7 @@ public function getResourceCode(): string return 'page'; } - private function resolveImage(PageContentInterface $page, string $url, string $locale): void + private function resolveImage(PageInterface $page, string $url, string $locale): void { /** @var PageTranslationInterface $pageTranslation */ $pageTranslation = $page->getTranslation($locale); diff --git a/src/Repository/PageRepository.php b/src/Repository/PageRepository.php index a82499a75..283f1fd56 100755 --- a/src/Repository/PageRepository.php +++ b/src/Repository/PageRepository.php @@ -12,7 +12,7 @@ namespace BitBag\SyliusCmsPlugin\Repository; -use BitBag\SyliusCmsPlugin\Entity\PageContentInterface; +use BitBag\SyliusCmsPlugin\Entity\PageInterface; use Doctrine\ORM\QueryBuilder; use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository; use Sylius\Component\Core\Model\ProductInterface; @@ -40,7 +40,7 @@ public function findEnabled(bool $enabled): array ; } - public function findOneEnabledByCode(string $code, ?string $localeCode): ?PageContentInterface + public function findOneEnabledByCode(string $code, ?string $localeCode): ?PageInterface { return $this->createQueryBuilder('o') ->leftJoin('o.translations', 'translation') @@ -58,7 +58,7 @@ public function findOneEnabledBySlugAndChannelCode( string $slug, ?string $localeCode, string $channelCode - ): ?PageContentInterface { + ): ?PageInterface { return $this->createQueryBuilder('o') ->leftJoin('o.translations', 'translation') ->innerJoin('o.channels', 'channels') diff --git a/src/Repository/PageRepositoryInterface.php b/src/Repository/PageRepositoryInterface.php index 7d55ebec2..8781fa7a1 100755 --- a/src/Repository/PageRepositoryInterface.php +++ b/src/Repository/PageRepositoryInterface.php @@ -12,7 +12,7 @@ namespace BitBag\SyliusCmsPlugin\Repository; -use BitBag\SyliusCmsPlugin\Entity\PageContentInterface; +use BitBag\SyliusCmsPlugin\Entity\PageInterface; use Doctrine\ORM\QueryBuilder; use Sylius\Component\Core\Model\ProductInterface; use Sylius\Component\Resource\Repository\RepositoryInterface; @@ -23,13 +23,13 @@ public function createListQueryBuilder(string $locale): QueryBuilder; public function findEnabled(bool $enabled): array; - public function findOneEnabledByCode(string $code, ?string $localeCode): ?PageContentInterface; + public function findOneEnabledByCode(string $code, ?string $localeCode): ?PageInterface; public function findOneEnabledBySlugAndChannelCode( string $slug, ?string $localeCode, string $channelCode - ): ?PageContentInterface; + ): ?PageInterface; public function createShopListQueryBuilder(string $sectionCode, string $channelCode): QueryBuilder; diff --git a/src/Resolver/PageResourceResolver.php b/src/Resolver/PageResourceResolver.php index c2aa84dcc..0a992e2f7 100755 --- a/src/Resolver/PageResourceResolver.php +++ b/src/Resolver/PageResourceResolver.php @@ -12,7 +12,7 @@ namespace BitBag\SyliusCmsPlugin\Resolver; -use BitBag\SyliusCmsPlugin\Entity\PageContentInterface; +use BitBag\SyliusCmsPlugin\Entity\PageInterface; use BitBag\SyliusCmsPlugin\Repository\PageRepositoryInterface; use Psr\Log\LoggerInterface; use Sylius\Component\Locale\Context\LocaleContextInterface; @@ -38,11 +38,11 @@ public function __construct( $this->logger = $logger; } - public function findOrLog(string $code): ?PageContentInterface + public function findOrLog(string $code): ?PageInterface { $page = $this->pageRepository->findOneEnabledByCode($code, $this->localeContext->getLocaleCode()); - if (false === $page instanceof PageContentInterface) { + if (false === $page instanceof PageInterface) { $this->logger->warning(sprintf( 'Page with "%s" code was not found in the database.', $code diff --git a/src/Resolver/PageResourceResolverInterface.php b/src/Resolver/PageResourceResolverInterface.php index d6da47f74..04ed98981 100755 --- a/src/Resolver/PageResourceResolverInterface.php +++ b/src/Resolver/PageResourceResolverInterface.php @@ -12,9 +12,9 @@ namespace BitBag\SyliusCmsPlugin\Resolver; -use BitBag\SyliusCmsPlugin\Entity\PageContentInterface; +use BitBag\SyliusCmsPlugin\Entity\PageInterface; interface PageResourceResolverInterface { - public function findOrLog(string $code): ?PageContentInterface; + public function findOrLog(string $code): ?PageInterface; } diff --git a/src/SitemapProvider/PageUrlProvider.php b/src/SitemapProvider/PageUrlProvider.php index 31b8a5ec4..c2ade4d62 100644 --- a/src/SitemapProvider/PageUrlProvider.php +++ b/src/SitemapProvider/PageUrlProvider.php @@ -12,7 +12,7 @@ namespace BitBag\SyliusCmsPlugin\SitemapProvider; -use BitBag\SyliusCmsPlugin\Entity\PageContentInterface; +use BitBag\SyliusCmsPlugin\Entity\PageInterface; use BitBag\SyliusCmsPlugin\Entity\PageTranslationInterface; use BitBag\SyliusCmsPlugin\Repository\PageRepositoryInterface; use Doctrine\Common\Collections\Collection; @@ -67,14 +67,14 @@ public function generate(): iterable { $urls = []; - foreach ($this->getPages() as $product) { - $urls[] = $this->createPageUrl($product); + foreach ($this->getPages() as $page) { + $urls[] = $this->createPageUrl($page); } return $urls; } - private function getTranslations(PageContentInterface $page): Collection + private function getTranslations(PageInterface $page): Collection { return $page->getTranslations()->filter(function (TranslationInterface $translation) { return $this->localeInLocaleCodes($translation); @@ -101,7 +101,7 @@ private function getLocaleCodes(): array })->toArray(); } - private function createPageUrl(PageContentInterface $page): SitemapUrlInterface + private function createPageUrl(PageInterface $page): SitemapUrlInterface { $pageUrl = $this->sitemapUrlFactory->createNew(); diff --git a/src/Twig/Extension/RenderProductPagesExtension.php b/src/Twig/Extension/RenderProductPagesExtension.php index 1acb12cfa..0c12ee171 100644 --- a/src/Twig/Extension/RenderProductPagesExtension.php +++ b/src/Twig/Extension/RenderProductPagesExtension.php @@ -12,7 +12,7 @@ namespace BitBag\SyliusCmsPlugin\Twig\Extension; -use BitBag\SyliusCmsPlugin\Entity\PageContentInterface; +use BitBag\SyliusCmsPlugin\Entity\PageInterface; use BitBag\SyliusCmsPlugin\Repository\PageRepositoryInterface; use Sylius\Component\Channel\Context\ChannelContextInterface; use Sylius\Component\Core\Model\ProductInterface; @@ -67,7 +67,7 @@ private function sortBySections(array $pages): array { $result = []; - /** @var PageContentInterface $page */ + /** @var PageInterface $page */ foreach ($pages as $page) { foreach ($page->getSections() as $section) { $sectionCode = $section->getCode(); diff --git a/tests/Behat/Context/Setup/PageContext.php b/tests/Behat/Context/Setup/PageContext.php index 20fba1f08..0428c2cad 100755 --- a/tests/Behat/Context/Setup/PageContext.php +++ b/tests/Behat/Context/Setup/PageContext.php @@ -14,7 +14,7 @@ use Behat\Behat\Context\Context; use BitBag\SyliusCmsPlugin\Entity\PageImage; -use BitBag\SyliusCmsPlugin\Entity\PageContentInterface; +use BitBag\SyliusCmsPlugin\Entity\PageInterface; use BitBag\SyliusCmsPlugin\Repository\PageRepositoryInterface; use BitBag\SyliusCmsPlugin\Repository\SectionRepositoryInterface; use Doctrine\ORM\EntityManagerInterface; @@ -204,7 +204,7 @@ public function thesePagesHaveThisSectionAssociatedWithIt(): void $section = $this->sharedStorage->get('section'); $pages = $this->pageRepository->findAll(); - /** @var PageContentInterface $page */ + /** @var PageInterface $page */ foreach ($pages as $page) { $page->addSection($section); } @@ -212,9 +212,9 @@ public function thesePagesHaveThisSectionAssociatedWithIt(): void $this->entityManager->flush(); } - private function createPage(?string $code = null, ?string $name = null, ?string $content = null, ChannelInterface $channel = null): PageContentInterface + private function createPage(?string $code = null, ?string $name = null, ?string $content = null, ChannelInterface $channel = null): PageInterface { - /** @var PageContentInterface $page */ + /** @var PageInterface $page */ $page = $this->pageFactory->createNew(); if (null === $channel && $this->sharedStorage->has('channel')) { @@ -255,7 +255,7 @@ private function uploadImage(string $name): ImageInterface return $image; } - private function savePage(PageContentInterface $page): void + private function savePage(PageInterface $page): void { $this->pageRepository->add($page); $this->sharedStorage->set('page', $page); From dcf54d87ea2c72312e518154ff152606366ec071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Kr=C3=B3l?= Date: Sun, 15 Jul 2018 18:49:46 +0200 Subject: [PATCH 2/6] Add media fixture --- src/Controller/MediaController.php | 1 - src/Fixture/Factory/BlockFixtureFactory.php | 5 +- src/Fixture/Factory/MediaFixtureFactory.php | 10 +++ src/Fixture/MediaFixture.php | 1 - src/Resources/config/services/fixture.yml | 18 ++++- .../views/Homepage/index.html.twig | 7 +- tests/Application/app/config/fixtures.yml | 76 +++++++------------ 7 files changed, 61 insertions(+), 57 deletions(-) diff --git a/src/Controller/MediaController.php b/src/Controller/MediaController.php index 39d47c716..ca4b9e860 100755 --- a/src/Controller/MediaController.php +++ b/src/Controller/MediaController.php @@ -51,7 +51,6 @@ public function downloadMediaAction(Request $request): Response $code = $request->get('code'); $mediaResourceResolver = $this->get('bitbag_sylius_cms_plugin.resolver.media_resource'); - /** @var MediaInterface $media */ $media = $mediaResourceResolver->findOrLog($code); diff --git a/src/Fixture/Factory/BlockFixtureFactory.php b/src/Fixture/Factory/BlockFixtureFactory.php index 2dffe4c11..dd344c8a3 100755 --- a/src/Fixture/Factory/BlockFixtureFactory.php +++ b/src/Fixture/Factory/BlockFixtureFactory.php @@ -15,7 +15,6 @@ use BitBag\SyliusCmsPlugin\Entity\BlockInterface; use BitBag\SyliusCmsPlugin\Entity\BlockTranslationInterface; use BitBag\SyliusCmsPlugin\Entity\SectionInterface; -use BitBag\SyliusCmsPlugin\Factory\BlockFactoryInterface; use BitBag\SyliusCmsPlugin\Repository\BlockRepositoryInterface; use BitBag\SyliusCmsPlugin\Repository\SectionRepositoryInterface; use Sylius\Component\Channel\Context\ChannelContextInterface; @@ -25,7 +24,7 @@ final class BlockFixtureFactory implements FixtureFactoryInterface { - /** @var BlockFactoryInterface */ + /** @var FactoryInterface */ private $blockFactory; /** @var FactoryInterface */ @@ -47,7 +46,7 @@ final class BlockFixtureFactory implements FixtureFactoryInterface private $localeContext; public function __construct( - BlockFactoryInterface $blockFactory, + FactoryInterface $blockFactory, FactoryInterface $blockTranslationFactory, BlockRepositoryInterface $blockRepository, SectionRepositoryInterface $sectionRepository, diff --git a/src/Fixture/Factory/MediaFixtureFactory.php b/src/Fixture/Factory/MediaFixtureFactory.php index 9dab706fb..ef0c9a7b8 100644 --- a/src/Fixture/Factory/MediaFixtureFactory.php +++ b/src/Fixture/Factory/MediaFixtureFactory.php @@ -16,8 +16,10 @@ use BitBag\SyliusCmsPlugin\Assigner\SectionsAssignerInterface; use BitBag\SyliusCmsPlugin\Entity\MediaInterface; use BitBag\SyliusCmsPlugin\Entity\MediaTranslationInterface; +use BitBag\SyliusCmsPlugin\MediaProvider\ProviderInterface; use BitBag\SyliusCmsPlugin\Repository\MediaRepositoryInterface; use Sylius\Component\Resource\Factory\FactoryInterface; +use Symfony\Component\HttpFoundation\File\File; final class MediaFixtureFactory implements FixtureFactoryInterface { @@ -27,6 +29,9 @@ final class MediaFixtureFactory implements FixtureFactoryInterface /** @var FactoryInterface */ private $mediaTranslationFactory; + /** @var ProviderInterface */ + private $imageProvider; + /** @var MediaRepositoryInterface */ private $mediaRepository; @@ -39,12 +44,14 @@ final class MediaFixtureFactory implements FixtureFactoryInterface public function __construct( FactoryInterface $mediaFactory, FactoryInterface $mediaTranslationFactory, + ProviderInterface $imageProvider, MediaRepositoryInterface $mediaRepository, ProductsAssignerInterface $productsAssigner, SectionsAssignerInterface $sectionsAssigner ) { $this->mediaFactory = $mediaFactory; $this->mediaTranslationFactory = $mediaTranslationFactory; + $this->imageProvider = $imageProvider; $this->mediaRepository = $mediaRepository; $this->productsAssigner = $productsAssigner; $this->sectionsAssigner = $sectionsAssigner; @@ -77,6 +84,9 @@ private function createMedia(string $code, array $mediaData): void $media->setType($mediaData['type']); $media->setCode($code); $media->setEnabled($mediaData['enabled']); + $media->setFile(new File($mediaData['path'])); + + $this->imageProvider->upload($media); foreach ($mediaData['translations'] as $localeCode => $translation) { /** @var MediaTranslationInterface $mediaTranslation */ diff --git a/src/Fixture/MediaFixture.php b/src/Fixture/MediaFixture.php index 9c8c7c966..ec3484a26 100644 --- a/src/Fixture/MediaFixture.php +++ b/src/Fixture/MediaFixture.php @@ -45,7 +45,6 @@ protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void ->children() ->booleanNode('remove_existing')->defaultTrue()->end() ->integerNode('number')->defaultNull()->end() - ->booleanNode('code')->isRequired()->cannotBeEmpty()->end() ->scalarNode('type')->isRequired()->cannotBeEmpty()->end() ->scalarNode('path')->isRequired()->cannotBeEmpty()->end() ->booleanNode('enabled')->defaultTrue()->end() diff --git a/src/Resources/config/services/fixture.yml b/src/Resources/config/services/fixture.yml index 058281a08..944debbee 100755 --- a/src/Resources/config/services/fixture.yml +++ b/src/Resources/config/services/fixture.yml @@ -27,6 +27,13 @@ services: tags: - { name: sylius_fixtures.fixture } + bitbag_sylius_cms_plugin.fixture.media: + class: BitBag\SyliusCmsPlugin\Fixture\MediaFixture + arguments: + - "@bitbag_sylius_cms_plugin.fixture.factory.media" + tags: + - { name: sylius_fixtures.fixture } + bitbag_sylius_cms_plugin.fixture.factory.block: class: BitBag\SyliusCmsPlugin\Fixture\Factory\BlockFixtureFactory arguments: @@ -34,7 +41,6 @@ services: - "@bitbag_sylius_cms_plugin.factory.block_translation" - "@bitbag_sylius_cms_plugin.repository.block" - "@bitbag_sylius_cms_plugin.repository.section" - - "@sylius.image_uploader" - "@sylius.repository.product" - "@sylius.context.channel" - "@sylius.context.locale" @@ -66,3 +72,13 @@ services: - "@bitbag_sylius_cms_plugin.factory.section_translation" - "@bitbag_sylius_cms_plugin.repository.section" - "@sylius.context.channel" + + bitbag_sylius_cms_plugin.fixture.factory.media: + class: BitBag\SyliusCmsPlugin\Fixture\Factory\MediaFixtureFactory + arguments: + - "@bitbag_sylius_cms_plugin.factory.media" + - "@bitbag_sylius_cms_plugin.factory.media_translation" + - "@bitbag_sylius_cms_plugin.media_provider.image" + - "@bitbag_sylius_cms_plugin.repository.media" + - "@bitbag_sylius_cms_plugin.assigner.products" + - "@bitbag_sylius_cms_plugin.assigner.sections" diff --git a/tests/Application/app/Resources/SyliusShopBundle/views/Homepage/index.html.twig b/tests/Application/app/Resources/SyliusShopBundle/views/Homepage/index.html.twig index 4da328650..4f4cf9cd8 100755 --- a/tests/Application/app/Resources/SyliusShopBundle/views/Homepage/index.html.twig +++ b/tests/Application/app/Resources/SyliusShopBundle/views/Homepage/index.html.twig @@ -25,19 +25,20 @@
- {{ bitbag_cms_render_block('homepage_banner_image_1') }} + {{ bitbag_cms_render_media('homepage_banner_image_1') }}
- {{ bitbag_cms_render_block('homepage_banner_image_2') }} + kurwa + {{ bitbag_cms_render_media('homepage_banner_image_2') }}
- {{ bitbag_cms_render_block('homepage_products_info') }} + {{ bitbag_cms_render_media('homepage_products_info') }}
diff --git a/tests/Application/app/config/fixtures.yml b/tests/Application/app/config/fixtures.yml index 2e8b4702b..446367bdc 100755 --- a/tests/Application/app/config/fixtures.yml +++ b/tests/Application/app/config/fixtures.yml @@ -34,43 +34,14 @@ sylius_fixtures: block: options: custom: - homepage_header_image: - type: image - translations: - en_US: - image_path: "%fixtures_dir%/homepage_header.jpeg" - name: | - Some block name - homepage_banner_image_1: - type: image - translations: - en_US: - image_path: "%fixtures_dir%/homepage_banner_1.jpeg" - link: "/en_US/page/about" - name: | - Click me! - homepage_banner_image_2: - type: image - translations: - en_US: - image_path: "%fixtures_dir%/homepage_banner_2.jpeg" homepage_products_info: - type: html translations: en_US: content: |
Click one of the below products to see what you can do with the blocks in your product view!
- sale: - type: image - sections: - - "products" - translations: - en_US: - image_path: "%fixtures_dir%/sale.jpeg" section_info_block: - type: html sections: - "products" translations: @@ -83,7 +54,6 @@ sylius_fixtures:

It's done with a simple controller render:

{{ render(path('bitbag_sylius_cms_plugin_shop_block_index_by_section_code', {'sectionCode' : 'products', 'template' : '@BitBagSyliusCmsPlugin/Shop/Block/index.html.twig'})) }}
product_info_block: - type: html products: 5 translations: en_US: @@ -92,14 +62,7 @@ sylius_fixtures:

This approach can be helpful with displaying some content dedicated to specific products, like size table or product story

The way you render it is similar to the one from above example:

{{ render(path('bitbag_sylius_cms_plugin_shop_block_index_by_product_code', {'productCode' : product.code, 'template' : '@BitBagSyliusCmsPlugin/Shop/Block/index.html.twig'})) }}
- size_table: - type: image - products: 5 - translations: - en_US: - image_path: "%fixtures_dir%/size_table.jpeg" homepage_intro: - type: html translations: en_US: content: | @@ -127,7 +90,6 @@ sylius_fixtures: The block with this nice woman is linked to another page. Click her and see what happens. No pornography included. I promise

lorem_ipsum: - type: text sections: - "homepage" translations: @@ -141,6 +103,34 @@ sylius_fixtures:
  • Pellentesque fermentum dolor. Aliquam quam lectus, facilisis auctor, ultrices ut, elementum vulputate, nunc.
  • Pellentesque habitant morbi tristique sene

    + media: + options: + custom: + homepage_header_image: + type: image + path: "%fixtures_dir%/homepage_header.jpeg" + translations: + en_US: + name: | + Some block name + homepage_banner_image_1: + type: image + path: "%fixtures_dir%/homepage_banner_1.jpeg" + translations: + en_US: + name: | + Click me! + homepage_banner_image_2: + type: image + path: "%fixtures_dir%/homepage_banner_2.jpeg" + size_table: + type: image + path: "%fixtures_dir%/size_table.jpeg" + sale: + type: image + path: "%fixtures_dir%/sale.jpeg" + sections: + - "products" page: options: custom: @@ -197,13 +187,3 @@ sylius_fixtures: Estne, quaeso, inquam, sitienti in bibendo voluptas? answer: | Nam his libris eum malo quam reliquo ornatu villae delectari. Quid est, quod ab ea absolvi et perfici debeat? Ex quo, id quod omnes expetunt, beate vivendi ratio inveniri et comparari potest. Stoici scilicet. - media: - options: - custom: - test_image: - translations: - en_US: - question: | - Estne, quaeso, inquam, sitienti in bibendo voluptas? - answer: | - Nam his libris eum malo quam reliquo ornatu villae delectari. Quid est, quod ab ea absolvi et perfici debeat? Ex quo, id quod omnes expetunt, beate vivendi ratio inveniri et comparari potest. Stoici scilicet. From 9c33b2b0c3a3fe042bd6e98fb0fb024fed2b4428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Kr=C3=B3l?= Date: Sun, 15 Jul 2018 20:47:14 +0200 Subject: [PATCH 3/6] Fix typo --- src/Twig/Extension/RenderMediaExtension.php | 10 +++++----- .../SyliusShopBundle/views/Homepage/index.html.twig | 1 - 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Twig/Extension/RenderMediaExtension.php b/src/Twig/Extension/RenderMediaExtension.php index 4f222f6e3..2437218af 100755 --- a/src/Twig/Extension/RenderMediaExtension.php +++ b/src/Twig/Extension/RenderMediaExtension.php @@ -40,11 +40,11 @@ public function getFunctions(): array public function renderMedia(string $code): string { - $media = $this->mediaResourceResolver->findOrLog($code); - - if (null !== $media) { - return $this->mediaProviderResolver->resolveProvider($media)->render($media); - } +// $media = $this->mediaResourceResolver->findOrLog($code); +// +// if (null !== $media) { +// return $this->mediaProviderResolver->resolveProvider($media)->render($media); +// } return ''; } diff --git a/tests/Application/app/Resources/SyliusShopBundle/views/Homepage/index.html.twig b/tests/Application/app/Resources/SyliusShopBundle/views/Homepage/index.html.twig index 4f4cf9cd8..1047e5edb 100755 --- a/tests/Application/app/Resources/SyliusShopBundle/views/Homepage/index.html.twig +++ b/tests/Application/app/Resources/SyliusShopBundle/views/Homepage/index.html.twig @@ -30,7 +30,6 @@
    - kurwa {{ bitbag_cms_render_media('homepage_banner_image_2') }}
    From 810e1903a443a052e3db2d9515445767a2ba37fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Kr=C3=B3l?= Date: Sun, 15 Jul 2018 21:35:42 +0200 Subject: [PATCH 4/6] Fix build --- src/Twig/Extension/RenderMediaExtension.php | 10 +++++----- tests/Application/app/config/fixtures.yml | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Twig/Extension/RenderMediaExtension.php b/src/Twig/Extension/RenderMediaExtension.php index 2437218af..4f222f6e3 100755 --- a/src/Twig/Extension/RenderMediaExtension.php +++ b/src/Twig/Extension/RenderMediaExtension.php @@ -40,11 +40,11 @@ public function getFunctions(): array public function renderMedia(string $code): string { -// $media = $this->mediaResourceResolver->findOrLog($code); -// -// if (null !== $media) { -// return $this->mediaProviderResolver->resolveProvider($media)->render($media); -// } + $media = $this->mediaResourceResolver->findOrLog($code); + + if (null !== $media) { + return $this->mediaProviderResolver->resolveProvider($media)->render($media); + } return ''; } diff --git a/tests/Application/app/config/fixtures.yml b/tests/Application/app/config/fixtures.yml index 446367bdc..ed038bbb4 100755 --- a/tests/Application/app/config/fixtures.yml +++ b/tests/Application/app/config/fixtures.yml @@ -71,7 +71,7 @@ sylius_fixtures: The left block is rendered with the usage of the particular controller like this:

    -                                                {{ render(path('bitbag_sylius_cms_plugin_shop_block_render', {'code' : 'homepage_header_image'})) }}
    +                                                render(path('bitbag_sylius_cms_plugin_shop_block_render', {'code' : 'homepage_header_image'}))
                                                     

    It also can take template as a parameter, but it's optional. In this case, it works the same as below Twig functions. Sometimes you might want the block to render in a different template, that's where the controller is useful. @@ -81,9 +81,9 @@ sylius_fixtures:

    -                                                {{ bitbag_cms_render_block('homepage_intro') }}
    -                                                {{ bitbag_cms_render_block('homepage_banner_image_1') }}
    -                                                {{ bitbag_cms_render_block('homepage_banner_image_2') }}
    +                                                bitbag_cms_render_block('homepage_intro')
    +                                                bitbag_cms_render_block('homepage_banner_image_1')
    +                                                bitbag_cms_render_block('homepage_banner_image_2')
                                                     

    From d173ea1c3769f05a4802a66b6a1bc8324cb99aa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Kr=C3=B3l?= Date: Sun, 15 Jul 2018 22:17:28 +0200 Subject: [PATCH 5/6] Add upgrade guide --- UPGRADE.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/UPGRADE.md b/UPGRADE.md index b20e15335..b4c4ff759 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,4 +1,16 @@ -# UPGRADE FROM 1.2.1/1.1.1 to 1.2.2-dev +# UPGRADE FROM 1.0 TO 2.0 + +* Media type field has been removed. For image blocks, use the [media](doc/medias.md) with image type. For HTML blocks, +use raw content in [WYSIWYG editor](doc/wysiwyg.md) +* Chanel awareness has been added to pages, blocks, FAQs, sections and media. That being said, many +repository methods changed their signatures. In case you customized them in your src, check +new signatures in interfaces under [BitBag\SyliusCmsPlugin\Repository](src/Repository) namespace +* WYSIWYG editor has been introduced. You will need to import it in your AppKernel and install +its assets. For more, check the [installation guide](doc/installation.md) +* Sitemap support was added, you will need to enable extra bundle in your AppKernel. Read more +in the [sitemap documentation](doc/sitemap.md) + +# UPGRADE FROM 1.2.1/1.1.1 to 1.2.2 * `bitbag_render_block` has been renamed to `bitbag_cms_render_block`. * Database tables has been prefixed with `bitbag_cms` instead of `bitbag_sylius_cms_plugin` for backward compatibility and simplicity. From 4f46e412ea96ccd21ce190114c59cfd51c7d7a6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Kr=C3=B3l?= Date: Sun, 15 Jul 2018 22:18:52 +0200 Subject: [PATCH 6/6] Add upgrade guide --- UPGRADE.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/UPGRADE.md b/UPGRADE.md index b4c4ff759..d75608bd1 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -9,6 +9,8 @@ new signatures in interfaces under [BitBag\SyliusCmsPlugin\Repository](src/Repos its assets. For more, check the [installation guide](doc/installation.md) * Sitemap support was added, you will need to enable extra bundle in your AppKernel. Read more in the [sitemap documentation](doc/sitemap.md) +* Because of the possibility to [nest CMS Twig functions in the admin backend](doc/twig-functions-in-admin.md), in order to render block and page content +you are now supposed to use `bitbag_cms_render_content` Twig function # UPGRADE FROM 1.2.1/1.1.1 to 1.2.2