From 660e8cd15d3178bf521cd09f5ab0ed74d2c5859d Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 10 Sep 2024 08:42:46 +0200 Subject: [PATCH 1/4] OP-515: Change service definition for content elements --- doc/content_elements.md | 28 +++-- .../Compiler/ContentElementPass.php | 57 ++++++++++ .../ContentElement/AbstractContentElement.php | 24 +++++ .../HeadingContentElementRenderer.php | 9 +- .../MultipleMediaContentElementRenderer.php | 6 +- .../PagesCollectionContentElementRenderer.php | 6 +- ...sCarouselByTaxonContentElementRenderer.php | 6 +- ...ProductsCarouselContentElementRenderer.php | 6 +- ...ductsGridByTaxonContentElementRenderer.php | 6 +- .../ProductsGridContentElementRenderer.php | 6 +- .../SingleMediaContentElementRenderer.php | 6 +- .../SpacerContentElementRenderer.php | 9 +- .../TaxonsListContentElementRenderer.php | 6 +- .../TextareaContentElementRenderer.php | 9 +- src/Resources/config/services/form.xml | 36 ------- src/Resources/config/services/renderer.xml | 100 +++++++++++------- src/SyliusCmsPlugin.php | 2 + 17 files changed, 187 insertions(+), 135 deletions(-) create mode 100644 src/DependencyInjection/Compiler/ContentElementPass.php create mode 100644 src/Renderer/ContentElement/AbstractContentElement.php diff --git a/doc/content_elements.md b/doc/content_elements.md index 468a3dea..8c75730a 100644 --- a/doc/content_elements.md +++ b/doc/content_elements.md @@ -55,34 +55,36 @@ final class TextContentElementType extends AbstractType } ``` -2. Define constant parameter in `config/parameters.yaml` or yours any other `yaml` file: +2. If your form type have constructor with some arguments, define constant parameter in `config/parameters.yaml` or yours any other `yaml` file: ```yaml parameters: sylius_cms.content_elements.type.text: !php/const 'YourNamespace\Form\Type\ContentElements\TextContentElementType::TYPE' ``` -3. Define form type in service container under `config/services.yml` with correct tags: +If your form type doesn't have any constructor arguments, you can skip this step, because compiler pass will automatically define it for you. + + +3. If your form type have constructor with some arguments, you must define form type in service container under `config/services.yml` with correct tags: ```yaml services: sylius_cms.form.type.content_element.text: class: YourNamespace\Form\Type\ContentElements\TextContentElementType + arguments: [...] tags: - { name: 'sylius_cms.content_elements.type', key: '%sylius_cms.content_elements.type.text%' } - { name: 'form.type' } ``` -4. Create a new renderer class under `src/Renderer/ContentElement` location. Implement `Sylius\CmsPlugin\Renderer\ContentElement\ContentElementRendererInterface` interface. +If your form type doesn't have any constructor arguments, you can skip this step, because compiler pass will automatically register it for you. + +4. Create a new renderer class under `src/Renderer/ContentElement` location. Extend `Sylius\CmsPlugin\Renderer\ContentElement\AbstractContentElement` class. For example, you can create a new renderer called `TextContentElementRenderer`: ```php -final class TextContentElementRenderer implements ContentElementRendererInterface +final class TextContentElementRenderer extends AbstractContentElement { - public function __construct(private Environment $twig) - { - } - public function supports(ContentConfigurationInterface $contentConfiguration): bool { return TextContentElementType::TYPE === $contentConfiguration->getType(); @@ -93,7 +95,7 @@ final class TextContentElementRenderer implements ContentElementRendererInterfac $text = $contentConfiguration->getConfiguration()['text']; return $this->twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [ - 'content_element' => '@YourNamespace/Shop/ContentElement/_text.html.twig', + 'content_element' => $this->template, 'text' => $text, ]); } @@ -109,9 +111,15 @@ services: arguments: - '@twig' tags: - - { name: 'sylius_cms.renderer.content_element' } + - { + name: 'sylius_cms.renderer.content_element', + template: '@YourNamespace/Shop/ContentElement/_text.html.twig', + form_type: 'YourNamespace\Form\Type\ContentElements\TextContentElementType' + } ``` +Define form_type only if your form type doesn't have constructor with additional arguments. + 6. Finally, create a new template under `templates/bundles/SyliusCmsPlugin/Shop/ContentElement` location. For example, you can create a new template called `_text.html.twig`: diff --git a/src/DependencyInjection/Compiler/ContentElementPass.php b/src/DependencyInjection/Compiler/ContentElementPass.php new file mode 100644 index 00000000..68558413 --- /dev/null +++ b/src/DependencyInjection/Compiler/ContentElementPass.php @@ -0,0 +1,57 @@ +findTaggedServiceIds('sylius_cms.content_element') as $id => $attributes) { + if (!isset($attributes[0]['template'])) { + throw new \InvalidArgumentException( + sprintf('Tagged content element "%s" needs to have `template` attribute.', $id), + ); + } + + $definition = $container->getDefinition($id); + $definition->addMethodCall('setTemplate', [$attributes[0]['template']]); + $definition->addMethodCall('setTwigEnvironment', [new Reference('twig')]); + + if (isset($attributes[0]['form_type'])) { + $this->registerFormTypeService($container, $attributes[0]['form_type']); + } + } + } + + private function retrieveElementNameConstantFromFormType(string $formType): string + { + if (!class_exists($formType)) { + throw new \InvalidArgumentException(sprintf('Form type "%s" does not exist.', $formType)); + } + + if (!defined($formType . '::TYPE')) { + throw new \InvalidArgumentException(sprintf('Form type "%s" needs to have "TYPE" constant.', $formType)); + } + + return constant(sprintf('%s::TYPE', $formType)); + } + + private function registerFormTypeService(ContainerBuilder $container, string $formType): void + { + $elementName = $this->retrieveElementNameConstantFromFormType($formType); + $formTypeDefinition = new Definition($formType); + $formTypeDefinition->addTag('form.type'); + $formTypeDefinition->addTag('sylius_cms.content_elements.type', [ + 'key' => $elementName, + ]); + + $container->setDefinition('sylius_cms.form.type.content_element.' . $elementName, $formTypeDefinition); + } +} diff --git a/src/Renderer/ContentElement/AbstractContentElement.php b/src/Renderer/ContentElement/AbstractContentElement.php new file mode 100644 index 00000000..919a2cff --- /dev/null +++ b/src/Renderer/ContentElement/AbstractContentElement.php @@ -0,0 +1,24 @@ +template = $template; + } + + public function setTwigEnvironment(Environment $twig): void + { + $this->twig = $twig; + } +} diff --git a/src/Renderer/ContentElement/HeadingContentElementRenderer.php b/src/Renderer/ContentElement/HeadingContentElementRenderer.php index d39486cc..3932f323 100644 --- a/src/Renderer/ContentElement/HeadingContentElementRenderer.php +++ b/src/Renderer/ContentElement/HeadingContentElementRenderer.php @@ -6,14 +6,9 @@ use Sylius\CmsPlugin\Entity\ContentConfigurationInterface; use Sylius\CmsPlugin\Form\Type\ContentElements\HeadingContentElementType; -use Twig\Environment; -final class HeadingContentElementRenderer implements ContentElementRendererInterface +final class HeadingContentElementRenderer extends AbstractContentElement { - public function __construct(private Environment $twig) - { - } - public function supports(ContentConfigurationInterface $contentConfiguration): bool { return HeadingContentElementType::TYPE === $contentConfiguration->getType(); @@ -26,7 +21,7 @@ public function render(ContentConfigurationInterface $contentConfiguration): str $headingContent = $configuration['heading']; return $this->twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [ - 'content_element' => '@SyliusCmsPlugin/Shop/ContentElement/_heading.html.twig', + 'content_element' => $this->template, 'heading_type' => $headingType, 'heading_content' => $headingContent, ]); diff --git a/src/Renderer/ContentElement/MultipleMediaContentElementRenderer.php b/src/Renderer/ContentElement/MultipleMediaContentElementRenderer.php index f12a6783..940221ee 100644 --- a/src/Renderer/ContentElement/MultipleMediaContentElementRenderer.php +++ b/src/Renderer/ContentElement/MultipleMediaContentElementRenderer.php @@ -9,12 +9,10 @@ use Sylius\CmsPlugin\Form\Type\ContentElements\MultipleMediaContentElementType; use Sylius\CmsPlugin\Repository\MediaRepositoryInterface; use Sylius\CmsPlugin\Twig\Runtime\RenderMediaRuntimeInterface; -use Twig\Environment; -final class MultipleMediaContentElementRenderer implements ContentElementRendererInterface +final class MultipleMediaContentElementRenderer extends AbstractContentElement { public function __construct( - private Environment $twig, private RenderMediaRuntimeInterface $renderMediaRuntime, private MediaRepositoryInterface $mediaRepository, ) { @@ -46,7 +44,7 @@ public function render(ContentConfigurationInterface $contentConfiguration): str } return $this->twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [ - 'content_element' => '@SyliusCmsPlugin/Shop/ContentElement/_multiple_media.html.twig', + 'content_element' => $this->template, 'media' => $media, ]); } diff --git a/src/Renderer/ContentElement/PagesCollectionContentElementRenderer.php b/src/Renderer/ContentElement/PagesCollectionContentElementRenderer.php index 66536d8d..09899c3b 100644 --- a/src/Renderer/ContentElement/PagesCollectionContentElementRenderer.php +++ b/src/Renderer/ContentElement/PagesCollectionContentElementRenderer.php @@ -8,12 +8,10 @@ use Sylius\CmsPlugin\Entity\ContentConfigurationInterface; use Sylius\CmsPlugin\Form\Type\ContentElements\PagesCollectionContentElementType; use Sylius\CmsPlugin\Repository\CollectionRepositoryInterface; -use Twig\Environment; -final class PagesCollectionContentElementRenderer implements ContentElementRendererInterface +final class PagesCollectionContentElementRenderer extends AbstractContentElement { public function __construct( - private Environment $twig, private CollectionRepositoryInterface $collectionRepository, ) { } @@ -34,7 +32,7 @@ public function render(ContentConfigurationInterface $contentConfiguration): str $collection = $this->collectionRepository->findOneBy(['code' => $code]); return $this->twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [ - 'content_element' => '@SyliusCmsPlugin/Shop/ContentElement/_pages_collection.html.twig', + 'content_element' => $this->template, 'collection' => $collection?->getPages(), ]); } diff --git a/src/Renderer/ContentElement/ProductsCarouselByTaxonContentElementRenderer.php b/src/Renderer/ContentElement/ProductsCarouselByTaxonContentElementRenderer.php index 3daf2033..a8963857 100644 --- a/src/Renderer/ContentElement/ProductsCarouselByTaxonContentElementRenderer.php +++ b/src/Renderer/ContentElement/ProductsCarouselByTaxonContentElementRenderer.php @@ -9,12 +9,10 @@ use Sylius\Component\Core\Model\TaxonInterface; use Sylius\Component\Core\Repository\ProductRepositoryInterface; use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface; -use Twig\Environment; -final class ProductsCarouselByTaxonContentElementRenderer implements ContentElementRendererInterface +final class ProductsCarouselByTaxonContentElementRenderer extends AbstractContentElement { public function __construct( - private Environment $twig, private ProductRepositoryInterface $productRepository, private TaxonRepositoryInterface $taxonRepository, ) { @@ -38,7 +36,7 @@ public function render(ContentConfigurationInterface $contentConfiguration): str $products = $this->productRepository->findByTaxon($taxon); return $this->twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [ - 'content_element' => '@SyliusCmsPlugin/Shop/ContentElement/_products_carousel.html.twig', + 'content_element' => $this->template, 'products' => $products, ]); } diff --git a/src/Renderer/ContentElement/ProductsCarouselContentElementRenderer.php b/src/Renderer/ContentElement/ProductsCarouselContentElementRenderer.php index 3baa2034..058f234d 100644 --- a/src/Renderer/ContentElement/ProductsCarouselContentElementRenderer.php +++ b/src/Renderer/ContentElement/ProductsCarouselContentElementRenderer.php @@ -7,12 +7,10 @@ use Sylius\CmsPlugin\Entity\ContentConfigurationInterface; use Sylius\CmsPlugin\Form\Type\ContentElements\ProductsCarouselContentElementType; use Sylius\Component\Core\Repository\ProductRepositoryInterface; -use Twig\Environment; -final class ProductsCarouselContentElementRenderer implements ContentElementRendererInterface +final class ProductsCarouselContentElementRenderer extends AbstractContentElement { public function __construct( - private Environment $twig, private ProductRepositoryInterface $productRepository, ) { } @@ -32,7 +30,7 @@ public function render(ContentConfigurationInterface $contentConfiguration): str } return $this->twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [ - 'content_element' => '@SyliusCmsPlugin/Shop/ContentElement/_products_carousel.html.twig', + 'content_element' => $this->template, 'products' => $products, ]); } diff --git a/src/Renderer/ContentElement/ProductsGridByTaxonContentElementRenderer.php b/src/Renderer/ContentElement/ProductsGridByTaxonContentElementRenderer.php index c678d28f..3f8743e1 100644 --- a/src/Renderer/ContentElement/ProductsGridByTaxonContentElementRenderer.php +++ b/src/Renderer/ContentElement/ProductsGridByTaxonContentElementRenderer.php @@ -9,12 +9,10 @@ use Sylius\Component\Core\Model\TaxonInterface; use Sylius\Component\Core\Repository\ProductRepositoryInterface; use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface; -use Twig\Environment; -final class ProductsGridByTaxonContentElementRenderer implements ContentElementRendererInterface +final class ProductsGridByTaxonContentElementRenderer extends AbstractContentElement { public function __construct( - private Environment $twig, private ProductRepositoryInterface $productRepository, private TaxonRepositoryInterface $taxonRepository, ) { @@ -38,7 +36,7 @@ public function render(ContentConfigurationInterface $contentConfiguration): str $products = $this->productRepository->findByTaxon($taxon); return $this->twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [ - 'content_element' => '@SyliusCmsPlugin/Shop/ContentElement/_products_grid.html.twig', + 'content_element' => $this->template, 'products' => $products, ]); } diff --git a/src/Renderer/ContentElement/ProductsGridContentElementRenderer.php b/src/Renderer/ContentElement/ProductsGridContentElementRenderer.php index 74026617..5fd30d31 100644 --- a/src/Renderer/ContentElement/ProductsGridContentElementRenderer.php +++ b/src/Renderer/ContentElement/ProductsGridContentElementRenderer.php @@ -7,12 +7,10 @@ use Sylius\CmsPlugin\Entity\ContentConfigurationInterface; use Sylius\CmsPlugin\Form\Type\ContentElements\ProductsGridContentElementType; use Sylius\Component\Core\Repository\ProductRepositoryInterface; -use Twig\Environment; -final class ProductsGridContentElementRenderer implements ContentElementRendererInterface +final class ProductsGridContentElementRenderer extends AbstractContentElement { public function __construct( - private Environment $twig, private ProductRepositoryInterface $productRepository, ) { } @@ -29,7 +27,7 @@ public function render(ContentConfigurationInterface $contentConfiguration): str $products = $this->productRepository->findBy(['code' => $productsCodes]); return $this->twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [ - 'content_element' => '@SyliusCmsPlugin/Shop/ContentElement/_products_grid.html.twig', + 'content_element' => $this->template, 'products' => $products, ]); } diff --git a/src/Renderer/ContentElement/SingleMediaContentElementRenderer.php b/src/Renderer/ContentElement/SingleMediaContentElementRenderer.php index 14cac90d..fb005ab1 100644 --- a/src/Renderer/ContentElement/SingleMediaContentElementRenderer.php +++ b/src/Renderer/ContentElement/SingleMediaContentElementRenderer.php @@ -8,12 +8,10 @@ use Sylius\CmsPlugin\Form\Type\ContentElements\SingleMediaContentElementType; use Sylius\CmsPlugin\Repository\MediaRepositoryInterface; use Sylius\CmsPlugin\Twig\Runtime\RenderMediaRuntimeInterface; -use Twig\Environment; -final class SingleMediaContentElementRenderer implements ContentElementRendererInterface +final class SingleMediaContentElementRenderer extends AbstractContentElement { public function __construct( - private Environment $twig, private RenderMediaRuntimeInterface $renderMediaRuntime, private MediaRepositoryInterface $mediaRepository, ) { @@ -37,7 +35,7 @@ public function render(ContentConfigurationInterface $contentConfiguration): str ]; return $this->twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [ - 'content_element' => '@SyliusCmsPlugin/Shop/ContentElement/_single_media.html.twig', + 'content_element' => $this->template, 'media' => $media, ]); } diff --git a/src/Renderer/ContentElement/SpacerContentElementRenderer.php b/src/Renderer/ContentElement/SpacerContentElementRenderer.php index 1988ac31..99dbc8c6 100644 --- a/src/Renderer/ContentElement/SpacerContentElementRenderer.php +++ b/src/Renderer/ContentElement/SpacerContentElementRenderer.php @@ -6,14 +6,9 @@ use Sylius\CmsPlugin\Entity\ContentConfigurationInterface; use Sylius\CmsPlugin\Form\Type\ContentElements\SpacerContentElementType; -use Twig\Environment; -final class SpacerContentElementRenderer implements ContentElementRendererInterface +final class SpacerContentElementRenderer extends AbstractContentElement { - public function __construct(private Environment $twig) - { - } - public function supports(ContentConfigurationInterface $contentConfiguration): bool { return SpacerContentElementType::TYPE === $contentConfiguration->getType(); @@ -24,7 +19,7 @@ public function render(ContentConfigurationInterface $contentConfiguration): str $configuration = (int) $contentConfiguration->getConfiguration()['spacer']; return $this->twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [ - 'content_element' => '@SyliusCmsPlugin/Shop/ContentElement/_spacer.html.twig', + 'content_element' => $this->template, 'spacer_height' => $configuration, ]); } diff --git a/src/Renderer/ContentElement/TaxonsListContentElementRenderer.php b/src/Renderer/ContentElement/TaxonsListContentElementRenderer.php index c3e93ef2..78c463b4 100644 --- a/src/Renderer/ContentElement/TaxonsListContentElementRenderer.php +++ b/src/Renderer/ContentElement/TaxonsListContentElementRenderer.php @@ -7,12 +7,10 @@ use Sylius\CmsPlugin\Entity\ContentConfigurationInterface; use Sylius\CmsPlugin\Form\Type\ContentElements\TaxonsListContentElementType; use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface; -use Twig\Environment; -final class TaxonsListContentElementRenderer implements ContentElementRendererInterface +final class TaxonsListContentElementRenderer extends AbstractContentElement { public function __construct( - private Environment $twig, private TaxonRepositoryInterface $taxonRepository, ) { } @@ -29,7 +27,7 @@ public function render(ContentConfigurationInterface $contentConfiguration): str $taxons = $this->taxonRepository->findBy(['code' => $taxonsCodes]); return $this->twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [ - 'content_element' => '@SyliusCmsPlugin/Shop/ContentElement/_taxons_list.html.twig', + 'content_element' => $this->template, 'taxons' => $taxons, ]); } diff --git a/src/Renderer/ContentElement/TextareaContentElementRenderer.php b/src/Renderer/ContentElement/TextareaContentElementRenderer.php index 2d090452..2b666d07 100644 --- a/src/Renderer/ContentElement/TextareaContentElementRenderer.php +++ b/src/Renderer/ContentElement/TextareaContentElementRenderer.php @@ -6,14 +6,9 @@ use Sylius\CmsPlugin\Entity\ContentConfigurationInterface; use Sylius\CmsPlugin\Form\Type\ContentElements\TextareaContentElementType; -use Twig\Environment; -final class TextareaContentElementRenderer implements ContentElementRendererInterface +final class TextareaContentElementRenderer extends AbstractContentElement { - public function __construct(private Environment $twig) - { - } - public function supports(ContentConfigurationInterface $contentConfiguration): bool { return TextareaContentElementType::TYPE === $contentConfiguration->getType(); @@ -22,7 +17,7 @@ public function supports(ContentConfigurationInterface $contentConfiguration): b public function render(ContentConfigurationInterface $contentConfiguration): string { return $this->twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [ - 'content_element' => '@SyliusCmsPlugin/Shop/ContentElement/_textarea.html.twig', + 'content_element' => $this->template, 'content' => $contentConfiguration->getConfiguration()['textarea'], ]); } diff --git a/src/Resources/config/services/form.xml b/src/Resources/config/services/form.xml index 65701c88..473585fc 100644 --- a/src/Resources/config/services/form.xml +++ b/src/Resources/config/services/form.xml @@ -2,17 +2,11 @@ - Sylius\CmsPlugin\Form\Type\ContentElements\TextareaContentElementType::TYPE Sylius\CmsPlugin\Form\Type\ContentElements\SingleMediaContentElementType::TYPE Sylius\CmsPlugin\Form\Type\ContentElements\MultipleMediaContentElementType::TYPE - Sylius\CmsPlugin\Form\Type\ContentElements\HeadingContentElementType::TYPE - Sylius\CmsPlugin\Form\Type\ContentElements\ProductsCarouselContentElementType::TYPE Sylius\CmsPlugin\Form\Type\ContentElements\ProductsCarouselByTaxonContentElementType::TYPE - Sylius\CmsPlugin\Form\Type\ContentElements\ProductsGridContentElementType::TYPE Sylius\CmsPlugin\Form\Type\ContentElements\ProductsGridByTaxonContentElementType::TYPE - Sylius\CmsPlugin\Form\Type\ContentElements\TaxonsListContentElementType::TYPE Sylius\CmsPlugin\Form\Type\ContentElements\PagesCollectionContentElementType::TYPE - Sylius\CmsPlugin\Form\Type\ContentElements\SpacerContentElementType::TYPE @@ -83,11 +77,6 @@ - - - - - @@ -101,16 +90,6 @@ - - - - - - - - - - @@ -118,11 +97,6 @@ - - - - - @@ -130,11 +104,6 @@ - - - - - @@ -142,11 +111,6 @@ - - - - - diff --git a/src/Resources/config/services/renderer.xml b/src/Resources/config/services/renderer.xml index abbd1ae7..106b8fba 100644 --- a/src/Resources/config/services/renderer.xml +++ b/src/Resources/config/services/renderer.xml @@ -6,74 +6,102 @@ - + - - - + + - - + - + - - + - + - - - + + - - + - + - - + - + - - + - + - - + - + - - + - + - - + - - - - - - + + + + + diff --git a/src/SyliusCmsPlugin.php b/src/SyliusCmsPlugin.php index c6bd295b..e186e8ef 100755 --- a/src/SyliusCmsPlugin.php +++ b/src/SyliusCmsPlugin.php @@ -5,6 +5,7 @@ namespace Sylius\CmsPlugin; use Sylius\Bundle\CoreBundle\Application\SyliusPluginTrait; +use Sylius\CmsPlugin\DependencyInjection\Compiler\ContentElementPass; use Sylius\CmsPlugin\DependencyInjection\Compiler\ImporterCompilerPass; use Sylius\CmsPlugin\DependencyInjection\Compiler\MediaProviderPass; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -20,5 +21,6 @@ public function build(ContainerBuilder $container): void $container->addCompilerPass(new ImporterCompilerPass()); $container->addCompilerPass(new MediaProviderPass()); + $container->addCompilerPass(new ContentElementPass()); } } From c388771f5890c427a77e42525c84ac807626ea0a Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 10 Sep 2024 08:56:47 +0200 Subject: [PATCH 2/4] OP-515: Spec fixes --- .../HeadingContentElementRendererSpec.php | 19 +++++++------------ ...ultipleMediaContentElementRendererSpec.php | 17 ++++++++--------- ...esCollectionContentElementRendererSpec.php | 17 +++++++++-------- ...ouselByTaxonContentElementRendererSpec.php | 18 +++++++++--------- ...uctsCarouselContentElementRendererSpec.php | 18 +++++++++--------- ...sGridByTaxonContentElementRendererSpec.php | 18 +++++++++--------- ...ProductsGridContentElementRendererSpec.php | 18 +++++++++--------- .../SingleMediaContentElementRendererSpec.php | 18 +++++++++--------- .../SpacerContentElementRendererSpec.php | 19 +++++++------------ .../TaxonsListContentElementRendererSpec.php | 18 +++++++++--------- .../TextareaContentElementRendererSpec.php | 19 +++++++------------ 11 files changed, 92 insertions(+), 107 deletions(-) diff --git a/spec/Renderer/ContentElement/HeadingContentElementRendererSpec.php b/spec/Renderer/ContentElement/HeadingContentElementRendererSpec.php index 2050bc4c..63e3d71c 100644 --- a/spec/Renderer/ContentElement/HeadingContentElementRendererSpec.php +++ b/spec/Renderer/ContentElement/HeadingContentElementRendererSpec.php @@ -7,25 +7,16 @@ use PhpSpec\ObjectBehavior; use Sylius\CmsPlugin\Entity\ContentConfigurationInterface; use Sylius\CmsPlugin\Form\Type\ContentElements\HeadingContentElementType; -use Sylius\CmsPlugin\Renderer\ContentElement\ContentElementRendererInterface; +use Sylius\CmsPlugin\Renderer\ContentElement\AbstractContentElement; use Sylius\CmsPlugin\Renderer\ContentElement\HeadingContentElementRenderer; use Twig\Environment; final class HeadingContentElementRendererSpec extends ObjectBehavior { - public function let(Environment $twig): void - { - $this->beConstructedWith($twig); - } - public function it_is_initializable(): void { $this->shouldHaveType(HeadingContentElementRenderer::class); - } - - public function it_implements_content_element_renderer_interface(): void - { - $this->shouldImplement(ContentElementRendererInterface::class); + $this->shouldBeAnInstanceOf(AbstractContentElement::class); } public function it_supports_heading_content_element_type(ContentConfigurationInterface $contentConfiguration): void @@ -42,13 +33,17 @@ public function it_does_not_support_other_content_element_types(ContentConfigura public function it_renders_heading_content_element(Environment $twig, ContentConfigurationInterface $contentConfiguration): void { + $template = 'custom_template'; + $this->setTemplate($template); + $this->setTwigEnvironment($twig); + $contentConfiguration->getConfiguration()->willReturn([ 'heading_type' => 'h1', 'heading' => 'Sample Heading', ]); $twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [ - 'content_element' => '@SyliusCmsPlugin/Shop/ContentElement/_heading.html.twig', + 'content_element' => $template, 'heading_type' => 'h1', 'heading_content' => 'Sample Heading', ])->willReturn('rendered template'); diff --git a/spec/Renderer/ContentElement/MultipleMediaContentElementRendererSpec.php b/spec/Renderer/ContentElement/MultipleMediaContentElementRendererSpec.php index f9549ed1..bbfae8d2 100644 --- a/spec/Renderer/ContentElement/MultipleMediaContentElementRendererSpec.php +++ b/spec/Renderer/ContentElement/MultipleMediaContentElementRendererSpec.php @@ -8,7 +8,7 @@ use Sylius\CmsPlugin\Entity\ContentConfigurationInterface; use Sylius\CmsPlugin\Entity\MediaInterface; use Sylius\CmsPlugin\Form\Type\ContentElements\MultipleMediaContentElementType; -use Sylius\CmsPlugin\Renderer\ContentElement\ContentElementRendererInterface; +use Sylius\CmsPlugin\Renderer\ContentElement\AbstractContentElement; use Sylius\CmsPlugin\Renderer\ContentElement\MultipleMediaContentElementRenderer; use Sylius\CmsPlugin\Repository\MediaRepositoryInterface; use Sylius\CmsPlugin\Twig\Runtime\RenderMediaRuntimeInterface; @@ -17,21 +17,16 @@ final class MultipleMediaContentElementRendererSpec extends ObjectBehavior { public function let( - Environment $twig, RenderMediaRuntimeInterface $renderMediaRuntime, MediaRepositoryInterface $mediaRepository, ): void { - $this->beConstructedWith($twig, $renderMediaRuntime, $mediaRepository); + $this->beConstructedWith($renderMediaRuntime, $mediaRepository); } public function it_is_initializable(): void { $this->shouldHaveType(MultipleMediaContentElementRenderer::class); - } - - public function it_implements_content_element_renderer_interface(): void - { - $this->shouldImplement(ContentElementRendererInterface::class); + $this->shouldBeAnInstanceOf(AbstractContentElement::class); } public function it_supports_multiple_media_content_element_type(ContentConfigurationInterface $contentConfiguration): void @@ -54,6 +49,10 @@ public function it_renders_multiple_media_content_element( MediaInterface $media1, MediaInterface $media2, ): void { + $template = 'custom_template'; + $this->setTemplate($template); + $this->setTwigEnvironment($twig); + $contentConfiguration->getConfiguration()->willReturn([ 'multiple_media' => ['code1', 'code2'], ]); @@ -67,7 +66,7 @@ public function it_renders_multiple_media_content_element( $renderMediaRuntime->renderMedia('code2')->willReturn('rendered media 2'); $twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [ - 'content_element' => '@SyliusCmsPlugin/Shop/ContentElement/_multiple_media.html.twig', + 'content_element' => $template, 'media' => [ [ 'renderedContent' => 'rendered media 1', diff --git a/spec/Renderer/ContentElement/PagesCollectionContentElementRendererSpec.php b/spec/Renderer/ContentElement/PagesCollectionContentElementRendererSpec.php index 17909029..97a5966c 100644 --- a/spec/Renderer/ContentElement/PagesCollectionContentElementRendererSpec.php +++ b/spec/Renderer/ContentElement/PagesCollectionContentElementRendererSpec.php @@ -9,6 +9,7 @@ use Sylius\CmsPlugin\Entity\CollectionInterface; use Sylius\CmsPlugin\Entity\ContentConfigurationInterface; use Sylius\CmsPlugin\Form\Type\ContentElements\PagesCollectionContentElementType; +use Sylius\CmsPlugin\Renderer\ContentElement\AbstractContentElement; use Sylius\CmsPlugin\Renderer\ContentElement\ContentElementRendererInterface; use Sylius\CmsPlugin\Renderer\ContentElement\PagesCollectionContentElementRenderer; use Sylius\CmsPlugin\Repository\CollectionRepositoryInterface; @@ -16,19 +17,15 @@ final class PagesCollectionContentElementRendererSpec extends ObjectBehavior { - public function let(Environment $twig, CollectionRepositoryInterface $collectionRepository): void + public function let(CollectionRepositoryInterface $collectionRepository): void { - $this->beConstructedWith($twig, $collectionRepository); + $this->beConstructedWith($collectionRepository); } public function it_is_initializable(): void { $this->shouldHaveType(PagesCollectionContentElementRenderer::class); - } - - public function it_implements_content_element_renderer_interface(): void - { - $this->shouldImplement(ContentElementRendererInterface::class); + $this->shouldBeAnInstanceOf(AbstractContentElement::class); } public function it_supports_pages_collection_content_element_type(ContentConfigurationInterface $contentConfiguration): void @@ -49,6 +46,10 @@ public function it_renders_pages_collection_content_element( ContentConfigurationInterface $contentConfiguration, CollectionInterface $collection, ): void { + $template = 'custom_template'; + $this->setTemplate($template); + $this->setTwigEnvironment($twig); + $contentConfiguration->getConfiguration()->willReturn([ 'pages_collection' => 'collection_code', ]); @@ -59,7 +60,7 @@ public function it_renders_pages_collection_content_element( $collection->getPages()->willReturn($pagesCollection); $twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [ - 'content_element' => '@SyliusCmsPlugin/Shop/ContentElement/_pages_collection.html.twig', + 'content_element' => $template, 'collection' => $pagesCollection, ])->willReturn('rendered_output'); diff --git a/spec/Renderer/ContentElement/ProductsCarouselByTaxonContentElementRendererSpec.php b/spec/Renderer/ContentElement/ProductsCarouselByTaxonContentElementRendererSpec.php index 9b106e50..b79c1ff6 100644 --- a/spec/Renderer/ContentElement/ProductsCarouselByTaxonContentElementRendererSpec.php +++ b/spec/Renderer/ContentElement/ProductsCarouselByTaxonContentElementRendererSpec.php @@ -7,7 +7,7 @@ use PhpSpec\ObjectBehavior; use Sylius\CmsPlugin\Entity\ContentConfigurationInterface; use Sylius\CmsPlugin\Form\Type\ContentElements\ProductsCarouselByTaxonContentElementType; -use Sylius\CmsPlugin\Renderer\ContentElement\ContentElementRendererInterface; +use Sylius\CmsPlugin\Renderer\ContentElement\AbstractContentElement; use Sylius\CmsPlugin\Renderer\ContentElement\ProductsCarouselByTaxonContentElementRenderer; use Sylius\Component\Core\Model\Product; use Sylius\Component\Core\Model\TaxonInterface; @@ -17,19 +17,15 @@ final class ProductsCarouselByTaxonContentElementRendererSpec extends ObjectBehavior { - public function let(Environment $twig, ProductRepositoryInterface $productRepository, TaxonRepositoryInterface $taxonRepository): void + public function let(ProductRepositoryInterface $productRepository, TaxonRepositoryInterface $taxonRepository): void { - $this->beConstructedWith($twig, $productRepository, $taxonRepository); + $this->beConstructedWith($productRepository, $taxonRepository); } public function it_is_initializable(): void { $this->shouldHaveType(ProductsCarouselByTaxonContentElementRenderer::class); - } - - public function it_implements_content_element_renderer_interface(): void - { - $this->shouldImplement(ContentElementRendererInterface::class); + $this->shouldBeAnInstanceOf(AbstractContentElement::class); } public function it_supports_products_carousel_by_taxon_content_element_type(ContentConfigurationInterface $contentConfiguration): void @@ -53,6 +49,10 @@ public function it_renders_products_carousel_by_taxon_content_element( Product $product1, Product $product2, ): void { + $template = 'custom_template'; + $this->setTemplate($template); + $this->setTwigEnvironment($twig); + $contentConfiguration->getConfiguration()->willReturn([ 'products_carousel_by_taxon' => 'taxon_code', ]); @@ -61,7 +61,7 @@ public function it_renders_products_carousel_by_taxon_content_element( $productRepository->findByTaxon($taxon)->willReturn([$product1, $product2]); $twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [ - 'content_element' => '@SyliusCmsPlugin/Shop/ContentElement/_products_carousel.html.twig', + 'content_element' => $template, 'products' => [$product1, $product2], ])->willReturn('rendered template'); diff --git a/spec/Renderer/ContentElement/ProductsCarouselContentElementRendererSpec.php b/spec/Renderer/ContentElement/ProductsCarouselContentElementRendererSpec.php index ac665426..91a25d74 100644 --- a/spec/Renderer/ContentElement/ProductsCarouselContentElementRendererSpec.php +++ b/spec/Renderer/ContentElement/ProductsCarouselContentElementRendererSpec.php @@ -7,7 +7,7 @@ use PhpSpec\ObjectBehavior; use Sylius\CmsPlugin\Entity\ContentConfigurationInterface; use Sylius\CmsPlugin\Form\Type\ContentElements\ProductsCarouselContentElementType; -use Sylius\CmsPlugin\Renderer\ContentElement\ContentElementRendererInterface; +use Sylius\CmsPlugin\Renderer\ContentElement\AbstractContentElement; use Sylius\CmsPlugin\Renderer\ContentElement\ProductsCarouselContentElementRenderer; use Sylius\Component\Core\Model\Product; use Sylius\Component\Core\Repository\ProductRepositoryInterface; @@ -15,19 +15,15 @@ final class ProductsCarouselContentElementRendererSpec extends ObjectBehavior { - public function let(Environment $twig, ProductRepositoryInterface $productRepository): void + public function let(ProductRepositoryInterface $productRepository): void { - $this->beConstructedWith($twig, $productRepository); + $this->beConstructedWith($productRepository); } public function it_is_initializable(): void { $this->shouldHaveType(ProductsCarouselContentElementRenderer::class); - } - - public function it_implements_content_element_renderer_interface(): void - { - $this->shouldImplement(ContentElementRendererInterface::class); + $this->shouldBeAnInstanceOf(AbstractContentElement::class); } public function it_supports_products_carousel_content_element_type(ContentConfigurationInterface $contentConfiguration): void @@ -49,6 +45,10 @@ public function it_renders_products_carousel_content_element( Product $product1, Product $product2, ): void { + $template = 'custom_template'; + $this->setTemplate($template); + $this->setTwigEnvironment($twig); + $contentConfiguration->getConfiguration()->willReturn([ 'products_carousel' => ['products' => ['code1', 'code2']], ]); @@ -56,7 +56,7 @@ public function it_renders_products_carousel_content_element( $productRepository->findBy(['code' => ['code1', 'code2']])->willReturn([$product1, $product2]); $twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [ - 'content_element' => '@SyliusCmsPlugin/Shop/ContentElement/_products_carousel.html.twig', + 'content_element' => $template, 'products' => [$product1, $product2], ])->willReturn('rendered template'); diff --git a/spec/Renderer/ContentElement/ProductsGridByTaxonContentElementRendererSpec.php b/spec/Renderer/ContentElement/ProductsGridByTaxonContentElementRendererSpec.php index b8d388b3..000108a5 100644 --- a/spec/Renderer/ContentElement/ProductsGridByTaxonContentElementRendererSpec.php +++ b/spec/Renderer/ContentElement/ProductsGridByTaxonContentElementRendererSpec.php @@ -7,7 +7,7 @@ use PhpSpec\ObjectBehavior; use Sylius\CmsPlugin\Entity\ContentConfigurationInterface; use Sylius\CmsPlugin\Form\Type\ContentElements\ProductsGridByTaxonContentElementType; -use Sylius\CmsPlugin\Renderer\ContentElement\ContentElementRendererInterface; +use Sylius\CmsPlugin\Renderer\ContentElement\AbstractContentElement; use Sylius\CmsPlugin\Renderer\ContentElement\ProductsGridByTaxonContentElementRenderer; use Sylius\Component\Core\Model\Product; use Sylius\Component\Core\Model\TaxonInterface; @@ -17,19 +17,15 @@ final class ProductsGridByTaxonContentElementRendererSpec extends ObjectBehavior { - public function let(Environment $twig, ProductRepositoryInterface $productRepository, TaxonRepositoryInterface $taxonRepository): void + public function let(ProductRepositoryInterface $productRepository, TaxonRepositoryInterface $taxonRepository): void { - $this->beConstructedWith($twig, $productRepository, $taxonRepository); + $this->beConstructedWith($productRepository, $taxonRepository); } public function it_is_initializable(): void { $this->shouldHaveType(ProductsGridByTaxonContentElementRenderer::class); - } - - public function it_implements_content_element_renderer_interface(): void - { - $this->shouldImplement(ContentElementRendererInterface::class); + $this->shouldBeAnInstanceOf(AbstractContentElement::class); } public function it_supports_products_grid_by_taxon_content_element_type(ContentConfigurationInterface $contentConfiguration): void @@ -53,6 +49,10 @@ public function it_renders_products_grid_by_taxon_content_element( Product $product1, Product $product2, ): void { + $template = 'custom_template'; + $this->setTemplate($template); + $this->setTwigEnvironment($twig); + $contentConfiguration->getConfiguration()->willReturn([ 'products_grid_by_taxon' => 'taxon_code', ]); @@ -61,7 +61,7 @@ public function it_renders_products_grid_by_taxon_content_element( $productRepository->findByTaxon($taxon)->willReturn([$product1, $product2]); $twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [ - 'content_element' => '@SyliusCmsPlugin/Shop/ContentElement/_products_grid.html.twig', + 'content_element' => $template, 'products' => [$product1, $product2], ])->willReturn('rendered template'); diff --git a/spec/Renderer/ContentElement/ProductsGridContentElementRendererSpec.php b/spec/Renderer/ContentElement/ProductsGridContentElementRendererSpec.php index d093c2d3..0c237bd4 100644 --- a/spec/Renderer/ContentElement/ProductsGridContentElementRendererSpec.php +++ b/spec/Renderer/ContentElement/ProductsGridContentElementRendererSpec.php @@ -7,7 +7,7 @@ use PhpSpec\ObjectBehavior; use Sylius\CmsPlugin\Entity\ContentConfigurationInterface; use Sylius\CmsPlugin\Form\Type\ContentElements\ProductsGridContentElementType; -use Sylius\CmsPlugin\Renderer\ContentElement\ContentElementRendererInterface; +use Sylius\CmsPlugin\Renderer\ContentElement\AbstractContentElement; use Sylius\CmsPlugin\Renderer\ContentElement\ProductsGridContentElementRenderer; use Sylius\Component\Core\Model\Product; use Sylius\Component\Core\Repository\ProductRepositoryInterface; @@ -15,19 +15,15 @@ final class ProductsGridContentElementRendererSpec extends ObjectBehavior { - public function let(Environment $twig, ProductRepositoryInterface $productRepository): void + public function let(ProductRepositoryInterface $productRepository): void { - $this->beConstructedWith($twig, $productRepository); + $this->beConstructedWith($productRepository); } public function it_is_initializable(): void { $this->shouldHaveType(ProductsGridContentElementRenderer::class); - } - - public function it_implements_content_element_renderer_interface(): void - { - $this->shouldImplement(ContentElementRendererInterface::class); + $this->shouldBeAnInstanceOf(AbstractContentElement::class); } public function it_supports_products_grid_content_element_type(ContentConfigurationInterface $contentConfiguration): void @@ -49,6 +45,10 @@ public function it_renders_products_grid_content_element( Product $product1, Product $product2, ): void { + $template = 'custom_template'; + $this->setTemplate($template); + $this->setTwigEnvironment($twig); + $contentConfiguration->getConfiguration()->willReturn([ 'products_grid' => ['products' => ['code1', 'code2']], ]); @@ -56,7 +56,7 @@ public function it_renders_products_grid_content_element( $productRepository->findBy(['code' => ['code1', 'code2']])->willReturn([$product1, $product2]); $twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [ - 'content_element' => '@SyliusCmsPlugin/Shop/ContentElement/_products_grid.html.twig', + 'content_element' => $template, 'products' => [$product1, $product2], ])->willReturn('rendered template'); diff --git a/spec/Renderer/ContentElement/SingleMediaContentElementRendererSpec.php b/spec/Renderer/ContentElement/SingleMediaContentElementRendererSpec.php index 28e18edc..d9a08cc2 100644 --- a/spec/Renderer/ContentElement/SingleMediaContentElementRendererSpec.php +++ b/spec/Renderer/ContentElement/SingleMediaContentElementRendererSpec.php @@ -8,7 +8,7 @@ use Sylius\CmsPlugin\Entity\ContentConfigurationInterface; use Sylius\CmsPlugin\Entity\MediaInterface; use Sylius\CmsPlugin\Form\Type\ContentElements\SingleMediaContentElementType; -use Sylius\CmsPlugin\Renderer\ContentElement\ContentElementRendererInterface; +use Sylius\CmsPlugin\Renderer\ContentElement\AbstractContentElement; use Sylius\CmsPlugin\Renderer\ContentElement\SingleMediaContentElementRenderer; use Sylius\CmsPlugin\Repository\MediaRepositoryInterface; use Sylius\CmsPlugin\Twig\Runtime\RenderMediaRuntimeInterface; @@ -16,19 +16,15 @@ final class SingleMediaContentElementRendererSpec extends ObjectBehavior { - public function let(Environment $twig, RenderMediaRuntimeInterface $renderMediaRuntime, MediaRepositoryInterface $mediaRepository): void + public function let(RenderMediaRuntimeInterface $renderMediaRuntime, MediaRepositoryInterface $mediaRepository): void { - $this->beConstructedWith($twig, $renderMediaRuntime, $mediaRepository); + $this->beConstructedWith($renderMediaRuntime, $mediaRepository); } public function it_is_initializable(): void { $this->shouldHaveType(SingleMediaContentElementRenderer::class); - } - - public function it_implements_content_element_renderer_interface(): void - { - $this->shouldImplement(ContentElementRendererInterface::class); + $this->shouldBeAnInstanceOf(AbstractContentElement::class); } public function it_supports_single_media_content_element_type(ContentConfigurationInterface $contentConfiguration): void @@ -50,6 +46,10 @@ public function it_renders_single_media_content_element( ContentConfigurationInterface $contentConfiguration, MediaInterface $media, ): void { + $template = 'custom_template'; + $this->setTemplate($template); + $this->setTwigEnvironment($twig); + $contentConfiguration->getConfiguration()->willReturn([ 'single_media' => 'media_code', ]); @@ -58,7 +58,7 @@ public function it_renders_single_media_content_element( $mediaRepository->findOneBy(['code' => 'media_code'])->willReturn($media); $twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [ - 'content_element' => '@SyliusCmsPlugin/Shop/ContentElement/_single_media.html.twig', + 'content_element' => $template, 'media' => [ 'renderedContent' => 'rendered media', 'entity' => $media, diff --git a/spec/Renderer/ContentElement/SpacerContentElementRendererSpec.php b/spec/Renderer/ContentElement/SpacerContentElementRendererSpec.php index a7972e21..79c8acc4 100644 --- a/spec/Renderer/ContentElement/SpacerContentElementRendererSpec.php +++ b/spec/Renderer/ContentElement/SpacerContentElementRendererSpec.php @@ -7,25 +7,16 @@ use PhpSpec\ObjectBehavior; use Sylius\CmsPlugin\Entity\ContentConfigurationInterface; use Sylius\CmsPlugin\Form\Type\ContentElements\SpacerContentElementType; -use Sylius\CmsPlugin\Renderer\ContentElement\ContentElementRendererInterface; +use Sylius\CmsPlugin\Renderer\ContentElement\AbstractContentElement; use Sylius\CmsPlugin\Renderer\ContentElement\SpacerContentElementRenderer; use Twig\Environment; final class SpacerContentElementRendererSpec extends ObjectBehavior { - public function let(Environment $twig): void - { - $this->beConstructedWith($twig); - } - public function it_is_initializable(): void { $this->shouldHaveType(SpacerContentElementRenderer::class); - } - - public function it_implements_content_element_renderer_interface(): void - { - $this->shouldImplement(ContentElementRendererInterface::class); + $this->shouldBeAnInstanceOf(AbstractContentElement::class); } public function it_supports_spacer_content_element_type(ContentConfigurationInterface $contentConfiguration): void @@ -42,12 +33,16 @@ public function it_does_not_support_other_content_element_types(ContentConfigura public function it_renders_spacer_content_element(Environment $twig, ContentConfigurationInterface $contentConfiguration): void { + $template = 'custom_template'; + $this->setTemplate($template); + $this->setTwigEnvironment($twig); + $contentConfiguration->getConfiguration()->willReturn([ 'spacer' => '40', ]); $twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [ - 'content_element' => '@SyliusCmsPlugin/Shop/ContentElement/_spacer.html.twig', + 'content_element' => $template, 'spacer_height' => '40', ])->willReturn('rendered template'); diff --git a/spec/Renderer/ContentElement/TaxonsListContentElementRendererSpec.php b/spec/Renderer/ContentElement/TaxonsListContentElementRendererSpec.php index 3fc7cc17..96fd44ea 100644 --- a/spec/Renderer/ContentElement/TaxonsListContentElementRendererSpec.php +++ b/spec/Renderer/ContentElement/TaxonsListContentElementRendererSpec.php @@ -7,7 +7,7 @@ use PhpSpec\ObjectBehavior; use Sylius\CmsPlugin\Entity\ContentConfigurationInterface; use Sylius\CmsPlugin\Form\Type\ContentElements\TaxonsListContentElementType; -use Sylius\CmsPlugin\Renderer\ContentElement\ContentElementRendererInterface; +use Sylius\CmsPlugin\Renderer\ContentElement\AbstractContentElement; use Sylius\CmsPlugin\Renderer\ContentElement\TaxonsListContentElementRenderer; use Sylius\Component\Core\Model\Taxon; use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface; @@ -15,19 +15,15 @@ final class TaxonsListContentElementRendererSpec extends ObjectBehavior { - public function let(Environment $twig, TaxonRepositoryInterface $taxonRepository): void + public function let(TaxonRepositoryInterface $taxonRepository): void { - $this->beConstructedWith($twig, $taxonRepository); + $this->beConstructedWith($taxonRepository); } public function it_is_initializable(): void { $this->shouldHaveType(TaxonsListContentElementRenderer::class); - } - - public function it_implements_content_element_renderer_interface(): void - { - $this->shouldImplement(ContentElementRendererInterface::class); + $this->shouldBeAnInstanceOf(AbstractContentElement::class); } public function it_supports_taxons_list_content_element_type(ContentConfigurationInterface $contentConfiguration): void @@ -49,6 +45,10 @@ public function it_renders_taxons_list_content_element( Taxon $taxon1, Taxon $taxon2, ): void { + $template = 'custom_template'; + $this->setTemplate($template); + $this->setTwigEnvironment($twig); + $contentConfiguration->getConfiguration()->willReturn([ 'taxons_list' => ['taxons' => ['code1', 'code2']], ]); @@ -56,7 +56,7 @@ public function it_renders_taxons_list_content_element( $taxonRepository->findBy(['code' => ['code1', 'code2']])->willReturn([$taxon1, $taxon2]); $twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [ - 'content_element' => '@SyliusCmsPlugin/Shop/ContentElement/_taxons_list.html.twig', + 'content_element' => $template, 'taxons' => [$taxon1, $taxon2], ])->willReturn('rendered template'); diff --git a/spec/Renderer/ContentElement/TextareaContentElementRendererSpec.php b/spec/Renderer/ContentElement/TextareaContentElementRendererSpec.php index ef584485..208ae280 100644 --- a/spec/Renderer/ContentElement/TextareaContentElementRendererSpec.php +++ b/spec/Renderer/ContentElement/TextareaContentElementRendererSpec.php @@ -7,25 +7,16 @@ use PhpSpec\ObjectBehavior; use Sylius\CmsPlugin\Entity\ContentConfigurationInterface; use Sylius\CmsPlugin\Form\Type\ContentElements\TextareaContentElementType; -use Sylius\CmsPlugin\Renderer\ContentElement\ContentElementRendererInterface; +use Sylius\CmsPlugin\Renderer\ContentElement\AbstractContentElement; use Sylius\CmsPlugin\Renderer\ContentElement\TextareaContentElementRenderer; use Twig\Environment; final class TextareaContentElementRendererSpec extends ObjectBehavior { - public function let(Environment $twig): void - { - $this->beConstructedWith($twig); - } - public function it_is_initializable(): void { $this->shouldHaveType(TextareaContentElementRenderer::class); - } - - public function it_implements_content_element_renderer_interface(): void - { - $this->shouldImplement(ContentElementRendererInterface::class); + $this->shouldBeAnInstanceOf(AbstractContentElement::class); } public function it_supports_textarea_content_element_type(ContentConfigurationInterface $contentConfiguration): void @@ -44,12 +35,16 @@ public function it_renders_textarea_content_element( Environment $twig, ContentConfigurationInterface $contentConfiguration, ): void { + $template = 'custom_template'; + $this->setTemplate($template); + $this->setTwigEnvironment($twig); + $contentConfiguration->getConfiguration()->willReturn([ 'textarea' => 'Textarea content', ]); $twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [ - 'content_element' => '@SyliusCmsPlugin/Shop/ContentElement/_textarea.html.twig', + 'content_element' => $template, 'content' => 'Textarea content', ])->willReturn('rendered template'); From 7a4c5ff6801aa7aed2f47b7cc9467711add13d05 Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 10 Sep 2024 12:06:47 +0200 Subject: [PATCH 3/4] OP-515: Remove use template button --- .../assets/admin/js/cms/cms-template.js | 19 +++++++++++++------ .../Modal/_loadTemplateConfirmation.html.twig | 2 +- src/Resources/views/Template/form.html.twig | 8 ++------ 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/Resources/assets/admin/js/cms/cms-template.js b/src/Resources/assets/admin/js/cms/cms-template.js index 0248477f..bee12f2a 100644 --- a/src/Resources/assets/admin/js/cms/cms-template.js +++ b/src/Resources/assets/admin/js/cms/cms-template.js @@ -5,14 +5,16 @@ export class HandleTemplate { const cmsPageTemplate = $('#sylius_cms_page_template'); const cmsBlockTemplate = $('#sylius_cms_block_template'); - cmsLoadTemplate.on('click', function (e) { - e.preventDefault(); - - if (!cmsPageTemplate.val() && !cmsBlockTemplate.val()) { - return; + cmsPageTemplate.on('change', function() { + if ($(this).val()) { + $('#load-template-confirmation-modal').modal('show'); } + }); - $('#load-template-confirmation-modal').modal('show'); + cmsBlockTemplate.on('change', function() { + if ($(this).val()) { + $('#load-template-confirmation-modal').modal('show'); + } }); $('#load-template-confirmation-button').on('click', function () { @@ -55,6 +57,11 @@ export class HandleTemplate { } }); }); + + $('#load-template-cancel-button').on('click', function () { + cmsPageTemplate.val(''); + cmsBlockTemplate.val(''); + }); }); } } diff --git a/src/Resources/views/Modal/_loadTemplateConfirmation.html.twig b/src/Resources/views/Modal/_loadTemplateConfirmation.html.twig index bad7ad06..e604811c 100644 --- a/src/Resources/views/Modal/_loadTemplateConfirmation.html.twig +++ b/src/Resources/views/Modal/_loadTemplateConfirmation.html.twig @@ -7,7 +7,7 @@

{{ 'sylius_cms.ui.load_template_confirmation_modal_text'|trans }}

-
+
{{ 'sylius.ui.no_label'|trans }}
diff --git a/src/Resources/views/Template/form.html.twig b/src/Resources/views/Template/form.html.twig index bf430f85..11f72e28 100644 --- a/src/Resources/views/Template/form.html.twig +++ b/src/Resources/views/Template/form.html.twig @@ -1,13 +1,9 @@
{{ 'sylius_cms.ui.use_page_template'|trans }}
-
+
{{ form_row(form.template) }} -
-
From 05d221b9fdde590cc69d24b815c3d92c7cfd16c5 Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 10 Sep 2024 12:31:01 +0200 Subject: [PATCH 4/4] OP-515: Behat fix --- features/admin/adding_block.feature | 1 - features/admin/adding_page.feature | 1 - tests/Behat/Context/Ui/Admin/BlockContext.php | 8 -------- tests/Behat/Context/Ui/Admin/PageContext.php | 8 -------- tests/Behat/Page/Admin/Block/CreatePage.php | 5 ----- tests/Behat/Page/Admin/Block/CreatePageInterface.php | 2 -- tests/Behat/Page/Admin/Page/CreatePage.php | 5 ----- tests/Behat/Page/Admin/Page/CreatePageInterface.php | 2 -- 8 files changed, 32 deletions(-) diff --git a/features/admin/adding_block.feature b/features/admin/adding_block.feature index 29dd78df..c721508e 100644 --- a/features/admin/adding_block.feature +++ b/features/admin/adding_block.feature @@ -187,7 +187,6 @@ Feature: Adding blocks And I fill the code with "intro" And I fill the name with "Intro" And I select "Homepage" template - And I click button to use this template And I confirm that I want to use this template And I add it Then I should be notified that the block has been created diff --git a/features/admin/adding_page.feature b/features/admin/adding_page.feature index b6df542d..9f2881eb 100644 --- a/features/admin/adding_page.feature +++ b/features/admin/adding_page.feature @@ -217,7 +217,6 @@ Feature: Adding new page And I fill the slug with "my_page" And I fill the name with "My page" And I select "Homepage" template - And I click button to use this template And I confirm that I want to use this template And I add it Then I should be notified that the page has been created diff --git a/tests/Behat/Context/Ui/Admin/BlockContext.php b/tests/Behat/Context/Ui/Admin/BlockContext.php index 73000094..92224332 100755 --- a/tests/Behat/Context/Ui/Admin/BlockContext.php +++ b/tests/Behat/Context/Ui/Admin/BlockContext.php @@ -408,14 +408,6 @@ public function iSelectTemplate(string $templateName): void $this->resolveCurrentPage()->selectTemplate($templateName); } - /** - * @Then I click button to use this template - */ - public function iClickButtonToUseThisTemplate(): void - { - $this->resolveCurrentPage()->useTemplate(); - } - /** * @Then I confirm that I want to use this template */ diff --git a/tests/Behat/Context/Ui/Admin/PageContext.php b/tests/Behat/Context/Ui/Admin/PageContext.php index b84480f7..bf984a82 100755 --- a/tests/Behat/Context/Ui/Admin/PageContext.php +++ b/tests/Behat/Context/Ui/Admin/PageContext.php @@ -299,14 +299,6 @@ public function iSelectTemplate(string $templateName): void $this->resolveCurrentPage()->selectTemplate($templateName); } - /** - * @Then I click button to use this template - */ - public function iClickButtonToUseThisTemplate(): void - { - $this->resolveCurrentPage()->useTemplate(); - } - /** * @Then I confirm that I want to use this template */ diff --git a/tests/Behat/Page/Admin/Block/CreatePage.php b/tests/Behat/Page/Admin/Block/CreatePage.php index 9378e0f9..15531ab3 100755 --- a/tests/Behat/Page/Admin/Block/CreatePage.php +++ b/tests/Behat/Page/Admin/Block/CreatePage.php @@ -267,11 +267,6 @@ public function selectTemplate(string $templateName): void $item->click(); } - public function useTemplate(): void - { - $this->getDocument()->findLink('Use this template')->click(); - } - public function confirmUseTemplate(): void { $this->getDocument()->findById('load-template-confirmation-button')->click(); diff --git a/tests/Behat/Page/Admin/Block/CreatePageInterface.php b/tests/Behat/Page/Admin/Block/CreatePageInterface.php index 01e17b41..59644f53 100755 --- a/tests/Behat/Page/Admin/Block/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Block/CreatePageInterface.php @@ -49,7 +49,5 @@ public function disable(): void; public function selectTemplate(string $templateName): void; - public function useTemplate(): void; - public function confirmUseTemplate(): void; } diff --git a/tests/Behat/Page/Admin/Page/CreatePage.php b/tests/Behat/Page/Admin/Page/CreatePage.php index cf5e63b7..7476451a 100755 --- a/tests/Behat/Page/Admin/Page/CreatePage.php +++ b/tests/Behat/Page/Admin/Page/CreatePage.php @@ -276,11 +276,6 @@ public function selectTemplate(string $templateName): void $item->click(); } - public function useTemplate(): void - { - $this->getDocument()->findLink('Use this template')->click(); - } - public function confirmUseTemplate(): void { $this->getDocument()->findById('load-template-confirmation-button')->click(); diff --git a/tests/Behat/Page/Admin/Page/CreatePageInterface.php b/tests/Behat/Page/Admin/Page/CreatePageInterface.php index 59fee985..3b533859 100755 --- a/tests/Behat/Page/Admin/Page/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Page/CreatePageInterface.php @@ -53,7 +53,5 @@ public function addTaxonsListContentElementWithTaxons(array $taxons): void; public function selectTemplate(string $templateName): void; - public function useTemplate(): void; - public function confirmUseTemplate(): void; }