From 6344164d463e62777f90567cc5e6f806f6765ca1 Mon Sep 17 00:00:00 2001 From: jkindly Date: Thu, 19 Sep 2024 12:45:47 +0200 Subject: [PATCH 1/8] OP-545: Translations --- src/Resources/translations/messages.cs.yml | 5 ++++- src/Resources/translations/messages.cs_CZ.yml | 5 ++++- src/Resources/translations/messages.de.yml | 5 ++++- src/Resources/translations/messages.en.yml | 5 ++++- src/Resources/translations/messages.es.yml | 5 ++++- src/Resources/translations/messages.fr.yml | 5 ++++- src/Resources/translations/messages.hr.yml | 5 ++++- src/Resources/translations/messages.lt.yml | 5 ++++- src/Resources/translations/messages.nl.yml | 5 ++++- src/Resources/translations/messages.pl.yml | 5 ++++- src/Resources/translations/messages.ru.yml | 5 ++++- src/Resources/translations/messages.sk.yml | 5 ++++- src/Resources/translations/messages.uk.yml | 5 ++++- 13 files changed, 52 insertions(+), 13 deletions(-) diff --git a/src/Resources/translations/messages.cs.yml b/src/Resources/translations/messages.cs.yml index 138695e2..490ff466 100755 --- a/src/Resources/translations/messages.cs.yml +++ b/src/Resources/translations/messages.cs.yml @@ -7,7 +7,7 @@ sylius_cms: page: Stránka title: Titul content_elements: - title: Obsahové prvky + title: Obsah type: textarea: Textarea single_media: Jediné médium @@ -22,6 +22,7 @@ sylius_cms: spacer: Oddělovač spacer_height: Výška oddělovače v pixelech heading_type: Typ nadpisu + template: Šablona prvků obsahu taxon: Taxon display_for_products: label: Zobrazit pro produkty @@ -34,6 +35,8 @@ sylius_cms: help: Vyberte taxony, ve kterých se bude tento blok zobrazovat manage_block_display: Správa zobrazení bloku templates: Šablony + template: Šablona + content_templates: Obsahové šablony new_template: Nová šablona edit_template: Upravit šablonu use_page_template: Použít šablonu stránky diff --git a/src/Resources/translations/messages.cs_CZ.yml b/src/Resources/translations/messages.cs_CZ.yml index 138695e2..490ff466 100755 --- a/src/Resources/translations/messages.cs_CZ.yml +++ b/src/Resources/translations/messages.cs_CZ.yml @@ -7,7 +7,7 @@ sylius_cms: page: Stránka title: Titul content_elements: - title: Obsahové prvky + title: Obsah type: textarea: Textarea single_media: Jediné médium @@ -22,6 +22,7 @@ sylius_cms: spacer: Oddělovač spacer_height: Výška oddělovače v pixelech heading_type: Typ nadpisu + template: Šablona prvků obsahu taxon: Taxon display_for_products: label: Zobrazit pro produkty @@ -34,6 +35,8 @@ sylius_cms: help: Vyberte taxony, ve kterých se bude tento blok zobrazovat manage_block_display: Správa zobrazení bloku templates: Šablony + template: Šablona + content_templates: Obsahové šablony new_template: Nová šablona edit_template: Upravit šablonu use_page_template: Použít šablonu stránky diff --git a/src/Resources/translations/messages.de.yml b/src/Resources/translations/messages.de.yml index 8a6c8b76..d1769c17 100755 --- a/src/Resources/translations/messages.de.yml +++ b/src/Resources/translations/messages.de.yml @@ -57,7 +57,7 @@ sylius_cms: successfully_imported: Die Daten wurden importiert. form_was_submitted_with_errors: "Das Formular wurde mit folgenden Fehlern übermittelt:" content_elements: - title: Inhalts-Elemente + title: Inhalt type: textarea: Textarea single_media: Einzelmedium @@ -72,6 +72,7 @@ sylius_cms: spacer: Abstandshalter spacer_height: Höhe des Abstandshalters in Pixeln heading_type: Überschrift-Typ + template: Inhaltselementvorlage taxon: Taxon display_for_products: label: Display für Produkte @@ -84,6 +85,8 @@ sylius_cms: help: Wählen Sie Taxonen aus, in denen dieser Block angezeigt wird manage_block_display: Blockanzeige verwalten templates: Vorlagen + template: Vorlage + content_templates: Inhaltsvorlagen new_template: Neue Vorlage edit_template: Vorlage bearbeiten use_page_template: Seitenschablone verwenden diff --git a/src/Resources/translations/messages.en.yml b/src/Resources/translations/messages.en.yml index 9d160b4b..bd4c1b0c 100755 --- a/src/Resources/translations/messages.en.yml +++ b/src/Resources/translations/messages.en.yml @@ -61,7 +61,7 @@ sylius_cms: page_will_be_publish_at: This page will be publish at save_with_original_name: Save with original name content_elements: - title: Content elements + title: Content type: textarea: Textarea single_media: Single media @@ -76,6 +76,7 @@ sylius_cms: spacer: Spacer spacer_height: Spacer height in pixels heading_type: Heading type + template: Content elements template taxon: Taxon seo: SEO display_for_products: @@ -89,6 +90,8 @@ sylius_cms: help: Select taxons in which this block will be displayed manage_block_display: Manage block display templates: Templates + template: Template + content_templates: Content Templates new_template: New template edit_template: Edit template use_page_template: Use page template diff --git a/src/Resources/translations/messages.es.yml b/src/Resources/translations/messages.es.yml index 53ee94a2..ab7c32b1 100755 --- a/src/Resources/translations/messages.es.yml +++ b/src/Resources/translations/messages.es.yml @@ -36,7 +36,7 @@ sylius_cms: position: Posición title: Título content_elements: - title: Elementos de contenido + title: Contenido type: textarea: Textarea single_media: Medio único @@ -51,6 +51,7 @@ sylius_cms: spacer: Separador spacer_height: Altura del separador en píxeles heading_type: Tipo de encabezado + template: Plantilla de elementos de contenido taxon: Taxón display_for_products: label: Mostrar para productos @@ -63,6 +64,8 @@ sylius_cms: help: Seleccione taxones en los que se mostrará este bloque manage_block_display: Administrar visualización de bloques templates: Plantillas + template: Plantilla + content_templates: Plantillas de contenido new_template: Nueva plantilla edit_template: Editar plantilla use_page_template: Usar plantilla de página diff --git a/src/Resources/translations/messages.fr.yml b/src/Resources/translations/messages.fr.yml index 4bf0e5c3..70d30e9c 100755 --- a/src/Resources/translations/messages.fr.yml +++ b/src/Resources/translations/messages.fr.yml @@ -54,7 +54,7 @@ sylius_cms: form_was_submitted_with_errors: "Le formulaire a les erreurs suivantes :" title: Titre content_elements: - title: Éléments de contenu + title: Contenu type: textarea: Textarea single_media: Média unique @@ -69,6 +69,7 @@ sylius_cms: spacer: Espacement spacer_height: Hauteur de l'espacement en pixels heading_type: Type d'en-tête + template: Modèle d'éléments de contenu taxon: Taxon display_for_products: label: Afficher pour les produits @@ -81,6 +82,8 @@ sylius_cms: help: Ce bloc sera affiché pour les taxons sélectionnés manage_block_display: Gérer l'affichage du bloc templates: Modèles + template: Modèle + content_templates: Modèles de contenu new_template: Nouveau modèle edit_template: Modifier le modèle use_page_template: Utiliser le modèle de page diff --git a/src/Resources/translations/messages.hr.yml b/src/Resources/translations/messages.hr.yml index 9c4f08be..f3d99745 100755 --- a/src/Resources/translations/messages.hr.yml +++ b/src/Resources/translations/messages.hr.yml @@ -36,7 +36,7 @@ sylius_cms: position: Pozicija (redosljed) title: Titula content_elements: - title: Elementi sadržaja + title: Sadržaj type: textarea: Textarea single_media: Jedan medij @@ -51,6 +51,7 @@ sylius_cms: spacer: Razmak spacer_height: Visina razmaka u pikselima heading_type: Tip naslova + template: Predložak elemenata sadržaja taxon: Takson display_for_products: label: Prikaz za proizvode @@ -63,6 +64,8 @@ sylius_cms: help: Odaberite taksone u kojima će se ovaj blok prikazati manage_block_display: Upravljanje prikazom bloka templates: Predlošci + template: Predložak + content_templates: Predloške sadržaja new_template: Novi predložak edit_template: Uredi predložak use_page_template: Koristi predložak stranice diff --git a/src/Resources/translations/messages.lt.yml b/src/Resources/translations/messages.lt.yml index 1613f8dd..b807a1eb 100644 --- a/src/Resources/translations/messages.lt.yml +++ b/src/Resources/translations/messages.lt.yml @@ -53,7 +53,7 @@ sylius_cms: successfully_imported: Duomenys sėkmingai importuoti. form_was_submitted_with_errors: "Forma pateikta su klaidomis:" content_elements: - title: Turinio elementai + title: Turinys type: textarea: Textarea single_media: Vienas medijos elementas @@ -68,6 +68,7 @@ sylius_cms: spacer: Tarpo elementas spacer_height: Tarpo aukštis pikseliais heading_type: Antraštės tipas + template: Turinio elementų šablonas taxon: Taksonas display_for_products: label: Rodyti produktams @@ -80,6 +81,8 @@ sylius_cms: help: Pasirinkite taksonus, kuriuose šis blokas bus rodomas manage_block_display: Bloko rodymo valdymas templates: Šablonai + template: Šablonas + content_templates: Turinys šablonai new_template: Naujas šablonas edit_template: Redaguoti šabloną use_page_template: Naudoti puslapio šabloną diff --git a/src/Resources/translations/messages.nl.yml b/src/Resources/translations/messages.nl.yml index 3ee4aee7..d107e9f9 100755 --- a/src/Resources/translations/messages.nl.yml +++ b/src/Resources/translations/messages.nl.yml @@ -35,7 +35,7 @@ sylius_cms: position: Positie title: Titel content_elements: - title: Inhoudselementen + title: Inhoud type: textarea: Textarea single_media: Enkel medium @@ -50,6 +50,7 @@ sylius_cms: spacer: Afstandhouder spacer_height: Hoogte van de afstandhouder in pixels heading_type: Kop type + template: Sjabloon voor inhoudselementen taxon: Taxon display_for_products: label: Display voor producten @@ -62,6 +63,8 @@ sylius_cms: help: Selecteer taxonen waarin dit blok wordt weergegeven manage_block_display: Beheer blok weergave templates: Sjablonen + template: Sjabloon + content_templates: Inhoudsjablonen new_template: Nieuwe sjabloon edit_template: Sjabloon bewerken use_page_template: Sjabloon voor pagina gebruiken diff --git a/src/Resources/translations/messages.pl.yml b/src/Resources/translations/messages.pl.yml index c56192f4..95fd2635 100755 --- a/src/Resources/translations/messages.pl.yml +++ b/src/Resources/translations/messages.pl.yml @@ -40,7 +40,7 @@ sylius_cms: page_will_be_publish_at: Strona zostanie opublikowana save_with_original_name: Zapisz z oryginalną nazwą content_elements: - title: Elementy treści + title: Treść type: textarea: Textarea single_media: Pojedyncze media @@ -55,6 +55,7 @@ sylius_cms: spacer: Odstęp spacer_height: Wysokość odstępu w pikselach heading_type: Typ nagłówka + template: Szablon elementów treści taxon: Taksonomia display_for_products: label: Wyświetlaj dla produktów @@ -67,6 +68,8 @@ sylius_cms: help: Wybież taksonomie, dla których ten blok będzie wyświetlany manage_block_display: Zarządzaj wyświetlaniem bloku templates: Szablony + template: Szablon + content_templates: Szablony treści new_template: Nowy szablon edit_template: Edytuj szablon use_page_template: Użyj szablonu strony diff --git a/src/Resources/translations/messages.ru.yml b/src/Resources/translations/messages.ru.yml index 15f0d76f..db928bf8 100755 --- a/src/Resources/translations/messages.ru.yml +++ b/src/Resources/translations/messages.ru.yml @@ -53,7 +53,7 @@ sylius_cms: successfully_imported: Данные успешно импортированы title: заглавие content_elements: - title: Элементы контента + title: Содержание type: textarea: Textarea single_media: Одиночный медиа @@ -68,6 +68,7 @@ sylius_cms: spacer: Пробел spacer_height: Высота пробела в пикселях heading_type: Тип заголовка + template: Шаблон элементов контента taxon: Таксон display_for_products: label: Отображать для товаров @@ -80,6 +81,8 @@ sylius_cms: help: Выберите таксоны, в которых будет отображаться этот блок manage_block_display: Управление отображением блоков templates: Шаблоны + template: Шаблон + content_templates: Шаблоны контента new_template: Новый шаблон edit_template: Редактировать шаблон use_page_template: Использовать шаблон страницы diff --git a/src/Resources/translations/messages.sk.yml b/src/Resources/translations/messages.sk.yml index c06934c1..57902b86 100644 --- a/src/Resources/translations/messages.sk.yml +++ b/src/Resources/translations/messages.sk.yml @@ -54,7 +54,7 @@ sylius_cms: form_was_submitted_with_errors: "Formulár obsahuje nasledovné chyby:" title: Titulok content_elements: - title: Obsahové prvky + title: Obsah type: textarea: Textarea single_media: Jedno médium @@ -69,6 +69,7 @@ sylius_cms: spacer: Medzera spacer_height: Výška medzery v pixeloch heading_type: Typ nadpisu + template: Šablóna prvkov obsahu taxon: Taxón display_for_products: label: Zobraziť pre produkty @@ -81,6 +82,8 @@ sylius_cms: help: Vyberte taxóny, v ktorých sa tento blok zobrazí manage_block_display: Spravovať zobrazenie bloku templates: Šablóny + template: Šablóna + content_templates: Šablóny obsahu new_template: Nová šablóna edit_template: Upraviť šablónu use_page_template: Použiť šablónu stránky diff --git a/src/Resources/translations/messages.uk.yml b/src/Resources/translations/messages.uk.yml index 0aa6e91a..3d339179 100755 --- a/src/Resources/translations/messages.uk.yml +++ b/src/Resources/translations/messages.uk.yml @@ -53,7 +53,7 @@ sylius_cms: successfully_imported: Дані успішно імпортовані title: заголовок content_elements: - title: Елементи контенту + title: Зміст type: textarea: Textarea single_media: Одиночне медіа @@ -68,6 +68,7 @@ sylius_cms: spacer: Роздільник spacer_height: Висота роздільника в пікселях heading_type: Тип заголовка + template: Шаблон елементів контенту taxon: Таксон display_for_products: label: Дисплей для продуктів @@ -80,6 +81,8 @@ sylius_cms: help: Виберіть таксони, в яких буде відображатися цей блок manage_block_display: Керування відображенням блоку templates: Шаблони + template: Шаблон + content_templates: Шаблони контенту new_template: Новий шаблон edit_template: Редагувати шаблон use_page_template: Використовувати шаблон сторінки From 1eb8aaee125cb83fa64a00faf4485eff322a65a8 Mon Sep 17 00:00:00 2001 From: jkindly Date: Thu, 19 Sep 2024 12:46:51 +0200 Subject: [PATCH 2/8] OP-545: Twig templates for blocks and pages --- .../Menu/ContentManagementMenuBuilderSpec.php | 2 +- src/Controller/BlockController.php | 10 +++-- src/Controller/PageController.php | 40 +++++++++++++++++ src/DependencyInjection/Configuration.php | 20 +++++++++ .../SyliusCmsExtension.php | 5 +++ src/Entity/Block.php | 12 +++++ src/Entity/BlockInterface.php | 4 ++ src/Entity/Page.php | 12 +++++ src/Entity/PageInterface.php | 4 ++ src/Form/Type/BlockType.php | 10 ++++- src/Form/Type/PageType.php | 30 ++++++++++++- src/Menu/ContentManagementMenuBuilder.php | 2 +- src/Migrations/Version20240918091924.php | 28 ++++++++++++ src/Provider/ResourceTemplateProvider.php | 45 +++++++++++++++++++ .../ResourceTemplateProviderInterface.php | 12 +++++ .../assets/admin/js/cms/cms-preview.js | 5 ++- src/Resources/config/doctrine/Block.orm.xml | 2 + src/Resources/config/doctrine/Page.orm.xml | 2 + src/Resources/config/routing/shop/page.yml | 8 ---- src/Resources/config/services/form.xml | 2 + src/Resources/config/services/provider.xml | 10 +++++ .../views/Block/Crud/_form.html.twig | 7 ++- src/Resources/views/Block/preview.html.twig | 12 ++--- .../Crud/_form.html.twig | 0 .../views/ContentTemplate/form.html.twig | 9 ++++ src/Resources/views/Locale/form.html.twig | 10 ++--- src/Resources/views/Page/Crud/_form.html.twig | 7 ++- src/Resources/views/Page/preview.html.twig | 2 +- src/Resources/views/Template/form.html.twig | 11 ++--- src/Twig/Runtime/RenderBlockRuntime.php | 4 +- 30 files changed, 283 insertions(+), 44 deletions(-) create mode 100644 src/Migrations/Version20240918091924.php create mode 100644 src/Provider/ResourceTemplateProvider.php create mode 100644 src/Provider/ResourceTemplateProviderInterface.php create mode 100644 src/Resources/config/services/provider.xml rename src/Resources/views/{Template => ContentTemplate}/Crud/_form.html.twig (100%) create mode 100644 src/Resources/views/ContentTemplate/form.html.twig diff --git a/spec/Menu/ContentManagementMenuBuilderSpec.php b/spec/Menu/ContentManagementMenuBuilderSpec.php index 57416a10..24c80662 100755 --- a/spec/Menu/ContentManagementMenuBuilderSpec.php +++ b/spec/Menu/ContentManagementMenuBuilderSpec.php @@ -55,7 +55,7 @@ public function it_build_menu( ->addChild('templates', ['route' => 'sylius_cms_admin_template_index']) ->willReturn($cmsRootMenuItem) ; - $cmsRootMenuItem->setLabel('sylius_cms.ui.templates')->willReturn($cmsRootMenuItem); + $cmsRootMenuItem->setLabel('sylius_cms.ui.content_templates')->willReturn($cmsRootMenuItem); $cmsRootMenuItem->setLabelAttribute('icon', 'clone')->shouldBeCalled(); $cmsRootMenuItem diff --git a/src/Controller/BlockController.php b/src/Controller/BlockController.php index 6abc54bf..3f43970e 100755 --- a/src/Controller/BlockController.php +++ b/src/Controller/BlockController.php @@ -7,6 +7,7 @@ use FOS\RestBundle\View\View; use Sylius\Bundle\ResourceBundle\Controller\ResourceController; use Sylius\CmsPlugin\Entity\BlockInterface; +use Sylius\CmsPlugin\Renderer\ContentElementRendererStrategyInterface; use Sylius\CmsPlugin\Resolver\BlockResourceResolverInterface; use Sylius\Component\Resource\ResourceActions; use Symfony\Component\HttpFoundation\Request; @@ -40,9 +41,7 @@ public function renderBlockAction(Request $request): Response return $this->viewHandler->handle($configuration, View::create($block)); } - $template = $request->get('template') ?? self::BLOCK_TEMPLATE; - - return $this->render($template, [ + return $this->render($block->getTemplate() ?? self::BLOCK_TEMPLATE, [ 'configuration' => $configuration, 'metadata' => $this->metadata, 'resource' => $block, @@ -70,8 +69,13 @@ public function previewAction(Request $request): Response return $this->viewHandler->handle($configuration, View::create($block)); } + /** @var ContentElementRendererStrategyInterface $contentElementRendererStrategy */ + $contentElementRendererStrategy = $this->get('sylius_cms.content_element_renderer_strategy'); + return $this->render($configuration->getTemplate(ResourceActions::CREATE . '.html'), [ 'resource' => $block, + 'template' => $block->getTemplate(), + 'content' => $contentElementRendererStrategy->render($block), $this->metadata->getName() => $block, ]); } diff --git a/src/Controller/PageController.php b/src/Controller/PageController.php index 6ee5ffb1..b06197d9 100755 --- a/src/Controller/PageController.php +++ b/src/Controller/PageController.php @@ -7,7 +7,10 @@ use FOS\RestBundle\View\View; use Sylius\Bundle\ResourceBundle\Controller\ResourceController; use Sylius\CmsPlugin\Entity\PageInterface; +use Sylius\CmsPlugin\Repository\PageRepositoryInterface; use Sylius\CmsPlugin\Resolver\PageResourceResolverInterface; +use Sylius\Component\Channel\Context\ChannelContextInterface; +use Sylius\Component\Locale\Context\LocaleContextInterface; use Sylius\Component\Resource\ResourceActions; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -22,6 +25,42 @@ final class PageController extends ResourceController public const FILTER = 'sylius_admin_product_original'; + public const DEFAULT_TEMPLATE = '@SyliusCmsPlugin/Shop/Page/show.html.twig'; + + public function showAction(Request $request): Response + { + $configuration = $this->getRequestConfiguration($request); + + $this->isGrantedOr403($configuration, ResourceActions::SHOW); + + $slug = $request->attributes->get('slug'); + + /** @var PageRepositoryInterface $pageRepository */ + $pageRepository = $this->get('sylius_cms.repository.page'); + + /** @var LocaleContextInterface $localeContext */ + $localeContext = $this->get('sylius.context.locale'); + + /** @var ChannelContextInterface $channelContext */ + $channelContext = $this->get('sylius.context.channel'); + + Assert::notNull($channelContext->getChannel()->getCode()); + + $page = $pageRepository->findOneEnabledBySlugAndChannelCode( + $slug, + $localeContext->getLocaleCode(), + $channelContext->getChannel()->getCode(), + ); + + if (null === $page) { + throw $this->createNotFoundException('Page not found'); + } + + return $this->render($page->getTemplate() ?? self::DEFAULT_TEMPLATE, [ + 'page' => $page, + ]); + } + public function renderLinkAction(Request $request): Response { $configuration = $this->getRequestConfiguration($request); @@ -78,6 +117,7 @@ public function previewAction(Request $request): Response return $this->render($configuration->getTemplate(ResourceActions::CREATE . '.html'), [ 'resource' => $page, 'preview' => true, + 'template' => $page->getTemplate() ?? self::DEFAULT_TEMPLATE, $this->metadata->getName() => $page, ]); } diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 9f30f0f0..20206897 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -52,6 +52,7 @@ public function getConfigTreeBuilder(): TreeBuilder $rootNode = $treeBuilder->getRootNode(); $this->addResourcesSection($rootNode); + $this->addTemplatesSection($rootNode); return $treeBuilder; } @@ -196,4 +197,23 @@ private function addResourcesSection(ArrayNodeDefinition $node): void ->end() ; } + + private function addTemplatesSection(ArrayNodeDefinition $node): void + { + $node + ->children() + ->arrayNode('templates') + ->addDefaultsIfNotSet() + ->children() + ->arrayNode('pages') + ->scalarPrototype()->end() + ->end() + ->arrayNode('blocks') + ->scalarPrototype()->end() + ->end() + ->end() + ->end() + ->end() + ; + } } diff --git a/src/DependencyInjection/SyliusCmsExtension.php b/src/DependencyInjection/SyliusCmsExtension.php index e9043147..19545c16 100755 --- a/src/DependencyInjection/SyliusCmsExtension.php +++ b/src/DependencyInjection/SyliusCmsExtension.php @@ -16,6 +16,11 @@ final class SyliusCmsExtension extends AbstractResourceExtension implements Prep public function load(array $configs, ContainerBuilder $container): void { + $configuration = new Configuration(); + $config = $this->processConfiguration($configuration, $configs); + + $container->setParameter('sylius_cms.templates.pages', $config['templates']['pages']); + $container->setParameter('sylius_cms.templates.blocks', $config['templates']['blocks']); } public function prepend(ContainerBuilder $container): void diff --git a/src/Entity/Block.php b/src/Entity/Block.php index e18a7d82..8d4555ad 100755 --- a/src/Entity/Block.php +++ b/src/Entity/Block.php @@ -38,6 +38,8 @@ public function __construct() protected ?string $name; + protected ?string $template = null; + public function getId(): ?int { return $this->id; @@ -62,4 +64,14 @@ public function setName(?string $name): void { $this->name = $name; } + + public function getTemplate(): ?string + { + return $this->template; + } + + public function setTemplate(?string $template): void + { + $this->template = $template; + } } diff --git a/src/Entity/BlockInterface.php b/src/Entity/BlockInterface.php index d3deca30..fd16e7f3 100755 --- a/src/Entity/BlockInterface.php +++ b/src/Entity/BlockInterface.php @@ -27,4 +27,8 @@ public function setCode(?string $code): void; public function getName(): ?string; public function setName(?string $name): void; + + public function getTemplate(): ?string; + + public function setTemplate(?string $template): void; } diff --git a/src/Entity/Page.php b/src/Entity/Page.php index 03f0e27f..20aa9e71 100755 --- a/src/Entity/Page.php +++ b/src/Entity/Page.php @@ -29,6 +29,8 @@ class Page implements PageInterface protected ?string $name = null; + protected ?string $template = null; + protected ?\DateTimeImmutable $publishAt; public function __construct() @@ -161,6 +163,16 @@ public function setName(?string $name): void $this->name = $name; } + public function getTemplate(): ?string + { + return $this->template; + } + + public function setTemplate(?string $template): void + { + $this->template = $template; + } + public function getTitle(): ?string { /** @var PageTranslationInterface $pageTranslationInterface */ diff --git a/src/Entity/PageInterface.php b/src/Entity/PageInterface.php index c3aafb98..0998a65c 100755 --- a/src/Entity/PageInterface.php +++ b/src/Entity/PageInterface.php @@ -38,6 +38,10 @@ public function getName(): ?string; public function setName(?string $name): void; + public function getTemplate(): ?string; + + public function setTemplate(?string $template): void; + public function getTitle(): ?string; public function setTitle(?string $title): void; diff --git a/src/Form/Type/BlockType.php b/src/Form/Type/BlockType.php index 497d8f21..bc4e1bc8 100755 --- a/src/Form/Type/BlockType.php +++ b/src/Form/Type/BlockType.php @@ -9,6 +9,7 @@ use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; use Sylius\Bundle\TaxonomyBundle\Form\Type\TaxonAutocompleteChoiceType; use Sylius\CmsPlugin\Entity\BlockInterface; +use Sylius\CmsPlugin\Provider\ResourceTemplateProviderInterface; use Sylius\Component\Locale\Model\LocaleInterface; use Sylius\Component\Resource\Repository\RepositoryInterface; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; @@ -23,6 +24,7 @@ final class BlockType extends AbstractResourceType public function __construct( private RepositoryInterface $localeRepository, + private ResourceTemplateProviderInterface $templateProvider, string $dataClass, array $validationGroups = [], ) { @@ -48,6 +50,11 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('name', TextType::class, [ 'label' => 'sylius_cms.ui.name', ]) + ->add('templates', ChoiceType::class, [ + 'label' => 'sylius_cms.ui.template', + 'choices' => $this->templateProvider->getBlockTemplates(), + 'mapped' => false, + ]) ->add('collections', CollectionAutocompleteChoiceType::class, [ 'label' => 'sylius_cms.ui.collections', 'multiple' => true, @@ -90,7 +97,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'multiple' => true, 'help' => 'sylius_cms.ui.display_for_taxons.help', ]) - ->add('template', TemplateBlockAutocompleteChoiceType::class, [ + ->add('contentTemplate', TemplateBlockAutocompleteChoiceType::class, [ 'label' => false, 'mapped' => false, ]) @@ -105,6 +112,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ; PageType::addContentElementLocaleListener($builder); + PageType::addTemplateListener($builder); } public function getBlockPrefix(): string diff --git a/src/Form/Type/PageType.php b/src/Form/Type/PageType.php index 6b02ddb7..0dbeba15 100755 --- a/src/Form/Type/PageType.php +++ b/src/Form/Type/PageType.php @@ -8,6 +8,7 @@ use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; use Sylius\Bundle\ResourceBundle\Form\Type\ResourceTranslationsType; use Sylius\CmsPlugin\Form\Type\Translation\PageTranslationType; +use Sylius\CmsPlugin\Provider\ResourceTemplateProviderInterface; use Sylius\Component\Locale\Model\LocaleInterface; use Sylius\Component\Resource\Repository\RepositoryInterface; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; @@ -25,6 +26,7 @@ final class PageType extends AbstractResourceType public function __construct( private RepositoryInterface $localeRepository, + private ResourceTemplateProviderInterface $templateProvider, string $dataClass, array $validationGroups = [], ) { @@ -47,6 +49,11 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('name', TextType::class, [ 'label' => 'sylius_cms.ui.name', ]) + ->add('templates', ChoiceType::class, [ + 'label' => 'sylius_cms.ui.template', + 'choices' => $this->templateProvider->getPageTemplates(), + 'mapped' => false, + ]) ->add('enabled', CheckboxType::class, [ 'label' => 'sylius_cms.ui.enabled', ]) @@ -85,7 +92,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'class' => 'content-elements-container', ], ]) - ->add('template', TemplatePageAutocompleteChoiceType::class, [ + ->add('contentTemplate', TemplatePageAutocompleteChoiceType::class, [ 'label' => false, 'mapped' => false, ]) @@ -100,6 +107,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ; self::addContentElementLocaleListener($builder); + self::addTemplateListener($builder); } public static function addContentElementLocaleListener(FormBuilderInterface $builder): void @@ -120,6 +128,26 @@ public static function addContentElementLocaleListener(FormBuilderInterface $bui }); } + public static function addTemplateListener(FormBuilderInterface $builder): void + { + $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) { + $form = $event->getForm(); + $data = $event->getData(); + $template = $data['templates'] ?? null; + + $entity = $form->getData(); + $entity->setTemplate($template); + }); + + $builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) { + $data = $event->getData(); + $form = $event->getForm(); + $template = $data->getTemplate(); + + $form->get('templates')->setData($template); + }); + } + public function getBlockPrefix(): string { return 'sylius_cms_page'; diff --git a/src/Menu/ContentManagementMenuBuilder.php b/src/Menu/ContentManagementMenuBuilder.php index e7ebf320..7f49fa18 100755 --- a/src/Menu/ContentManagementMenuBuilder.php +++ b/src/Menu/ContentManagementMenuBuilder.php @@ -33,7 +33,7 @@ public function buildMenu(MenuBuilderEvent $menuBuilderEvent): void ->addChild('templates', [ 'route' => 'sylius_cms_admin_template_index', ]) - ->setLabel('sylius_cms.ui.templates') + ->setLabel('sylius_cms.ui.content_templates') ->setLabelAttribute('icon', 'clone') ; diff --git a/src/Migrations/Version20240918091924.php b/src/Migrations/Version20240918091924.php new file mode 100644 index 00000000..cc3e3024 --- /dev/null +++ b/src/Migrations/Version20240918091924.php @@ -0,0 +1,28 @@ +addSql('ALTER TABLE sylius_cms_block ADD template VARCHAR(250) DEFAULT NULL'); + $this->addSql('ALTER TABLE sylius_cms_page ADD template VARCHAR(250) DEFAULT NULL'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE sylius_cms_block DROP template'); + $this->addSql('ALTER TABLE sylius_cms_page DROP template'); + } +} diff --git a/src/Provider/ResourceTemplateProvider.php b/src/Provider/ResourceTemplateProvider.php new file mode 100644 index 00000000..5ec65d34 --- /dev/null +++ b/src/Provider/ResourceTemplateProvider.php @@ -0,0 +1,45 @@ +get('sylius_cms.templates.pages'))) { + $this->templates['pages'] = $params->get('sylius_cms.templates.pages'); + } + + if (is_array($params->get('sylius_cms.templates.blocks'))) { + $this->templates['blocks'] = $params->get('sylius_cms.templates.blocks'); + } + } + + public function getPageTemplates(): array + { + $keys = ['sylius.ui.default']; + $values = ['@SyliusCmsPlugin/Shop/Page/show.html.twig']; + + return array_combine( + array_merge($keys, $this->templates['pages']), + array_merge($values, $this->templates['pages']), + ); + } + + public function getBlockTemplates(): array + { + $keys = ['sylius.ui.default']; + $values = ['@SyliusCmsPlugin/Shop/Block/show.html.twig']; + + return array_combine( + array_merge($keys, $this->templates['blocks']), + array_merge($values, $this->templates['blocks']), + ); + } +} diff --git a/src/Provider/ResourceTemplateProviderInterface.php b/src/Provider/ResourceTemplateProviderInterface.php new file mode 100644 index 00000000..34536ea2 --- /dev/null +++ b/src/Provider/ResourceTemplateProviderInterface.php @@ -0,0 +1,12 @@ + instance.updateElement()); + if (typeof CKEDITOR !== 'undefined') { + Object.values(CKEDITOR.instances).forEach((instance) => instance.updateElement()); + } } - _resourcePreview() { this.button.addEventListener('click', (e) => { e.preventDefault(); diff --git a/src/Resources/config/doctrine/Block.orm.xml b/src/Resources/config/doctrine/Block.orm.xml index fea56d10..91497e03 100644 --- a/src/Resources/config/doctrine/Block.orm.xml +++ b/src/Resources/config/doctrine/Block.orm.xml @@ -14,6 +14,8 @@ + + diff --git a/src/Resources/config/doctrine/Page.orm.xml b/src/Resources/config/doctrine/Page.orm.xml index 4f4a081a..2db129e9 100644 --- a/src/Resources/config/doctrine/Page.orm.xml +++ b/src/Resources/config/doctrine/Page.orm.xml @@ -17,6 +17,8 @@ + + diff --git a/src/Resources/config/routing/shop/page.yml b/src/Resources/config/routing/shop/page.yml index 9d8f2d92..d015cf27 100755 --- a/src/Resources/config/routing/shop/page.yml +++ b/src/Resources/config/routing/shop/page.yml @@ -3,14 +3,6 @@ sylius_cms_shop_page_show: methods: [GET] defaults: _controller: sylius_cms.controller.page.overriden::showAction - _sylius: - template: "@SyliusCmsPlugin/Shop/Page/show.html.twig" - repository: - method: findOneEnabledBySlugAndChannelCode - arguments: - - $slug - - "expr:service('sylius.context.locale').getLocaleCode()" - - "expr:service('sylius.context.channel').getChannel().getCode()" sylius_cms_shop_page_show_link_by_code: path: /page/link/{code} diff --git a/src/Resources/config/services/form.xml b/src/Resources/config/services/form.xml index 1d517afc..a9d3016f 100644 --- a/src/Resources/config/services/form.xml +++ b/src/Resources/config/services/form.xml @@ -14,6 +14,7 @@ + %sylius_cms.model.block.class% %sylius_cms.form.type.block.validation_groups% @@ -29,6 +30,7 @@ + %sylius_cms.model.page.class% %sylius_cms.form.type.page.validation_groups% diff --git a/src/Resources/config/services/provider.xml b/src/Resources/config/services/provider.xml new file mode 100644 index 00000000..eac63dbd --- /dev/null +++ b/src/Resources/config/services/provider.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/Resources/views/Block/Crud/_form.html.twig b/src/Resources/views/Block/Crud/_form.html.twig index 23c58060..a056ec1b 100755 --- a/src/Resources/views/Block/Crud/_form.html.twig +++ b/src/Resources/views/Block/Crud/_form.html.twig @@ -33,8 +33,11 @@

{{ 'sylius_cms.ui.content_elements.title'|trans }}

- {% include '@SyliusCmsPlugin/Template/form.html.twig' with {ajax_url: path('sylius_cms_admin_ajax_template_content_by_id', {'id': 'REPLACE_ID'}) } %} - {% include '@SyliusCmsPlugin/Locale/form.html.twig' %} +
+ {% include '@SyliusCmsPlugin/Locale/form.html.twig' %} + {% include '@SyliusCmsPlugin/Template/form.html.twig' %} +
+ {% include '@SyliusCmsPlugin/ContentTemplate/form.html.twig' with {ajax_url: path('sylius_cms_admin_ajax_template_content_by_id', {'id': 'REPLACE_ID'}) } %}
{{ form_row(form.contentElements) }} diff --git a/src/Resources/views/Block/preview.html.twig b/src/Resources/views/Block/preview.html.twig index 9d8eb74c..9f6f1c8d 100755 --- a/src/Resources/views/Block/preview.html.twig +++ b/src/Resources/views/Block/preview.html.twig @@ -1,13 +1,9 @@ {% extends '@SyliusShop/layout.html.twig' %} -{% block metatags %} - +{% block content %} + {% include template %} {% endblock %} -{% block content %} -
-
- {{ sylius_cms_render_content_elements(block) }} -
-
+{% block metatags %} + {% endblock %} diff --git a/src/Resources/views/Template/Crud/_form.html.twig b/src/Resources/views/ContentTemplate/Crud/_form.html.twig similarity index 100% rename from src/Resources/views/Template/Crud/_form.html.twig rename to src/Resources/views/ContentTemplate/Crud/_form.html.twig diff --git a/src/Resources/views/ContentTemplate/form.html.twig b/src/Resources/views/ContentTemplate/form.html.twig new file mode 100644 index 00000000..0b8d0e5d --- /dev/null +++ b/src/Resources/views/ContentTemplate/form.html.twig @@ -0,0 +1,9 @@ +
+
{{ 'sylius_cms.ui.content_elements.template'|trans }}
+
+
+ {{ form_row(form.contentTemplate) }} + +
+
+
diff --git a/src/Resources/views/Locale/form.html.twig b/src/Resources/views/Locale/form.html.twig index a18cb691..d50ad859 100644 --- a/src/Resources/views/Locale/form.html.twig +++ b/src/Resources/views/Locale/form.html.twig @@ -1,8 +1,6 @@ -
-
{{ form_label(form.locale) }}
-
-
- {{ form_widget(form.locale) }} -
+
{{ form_label(form.locale) }}
+
+
+ {{ form_widget(form.locale) }}
diff --git a/src/Resources/views/Page/Crud/_form.html.twig b/src/Resources/views/Page/Crud/_form.html.twig index fb9384da..dab46ea2 100755 --- a/src/Resources/views/Page/Crud/_form.html.twig +++ b/src/Resources/views/Page/Crud/_form.html.twig @@ -42,8 +42,11 @@

{{ 'sylius_cms.ui.content_elements.title'|trans }}

- {% include '@SyliusCmsPlugin/Template/form.html.twig' with {ajax_url: path('sylius_cms_admin_ajax_template_content_by_id', {'id': 'REPLACE_ID'}) } %} - {% include '@SyliusCmsPlugin/Locale/form.html.twig' %} +
+ {% include '@SyliusCmsPlugin/Locale/form.html.twig' %} + {% include '@SyliusCmsPlugin/Template/form.html.twig' %} +
+ {% include '@SyliusCmsPlugin/ContentTemplate/form.html.twig' with {ajax_url: path('sylius_cms_admin_ajax_template_content_by_id', {'id': 'REPLACE_ID'}) } %}
{{ form_row(form.contentElements) }} diff --git a/src/Resources/views/Page/preview.html.twig b/src/Resources/views/Page/preview.html.twig index 7530b93b..8e9530a6 100644 --- a/src/Resources/views/Page/preview.html.twig +++ b/src/Resources/views/Page/preview.html.twig @@ -1,4 +1,4 @@ -{% extends "@SyliusCmsPlugin/Shop/Page/show.html.twig" %} +{% extends template %} {% block metatags %} diff --git a/src/Resources/views/Template/form.html.twig b/src/Resources/views/Template/form.html.twig index 11f72e28..fd2f4672 100644 --- a/src/Resources/views/Template/form.html.twig +++ b/src/Resources/views/Template/form.html.twig @@ -1,9 +1,6 @@ -
-
{{ 'sylius_cms.ui.use_page_template'|trans }}
-
-
- {{ form_row(form.template) }} - -
+
{{ form_label(form.templates) }}
+
+
+ {{ form_widget(form.templates) }}
diff --git a/src/Twig/Runtime/RenderBlockRuntime.php b/src/Twig/Runtime/RenderBlockRuntime.php index 7f98f275..fc76d405 100644 --- a/src/Twig/Runtime/RenderBlockRuntime.php +++ b/src/Twig/Runtime/RenderBlockRuntime.php @@ -39,8 +39,10 @@ public function renderBlock(string $code, ?string $template = null, ProductInter return ''; } + $blockTemplate = $template ?? $block->getTemplate(); + return $this->templatingEngine->render( - $template ?? self::DEFAULT_TEMPLATE, + $blockTemplate ?? self::DEFAULT_TEMPLATE, [ 'content' => $this->contentElementRendererStrategy->render($block), 'context' => $context, From f1ad2ce2aaa3e6d08a6f813eb6230818ac4dd97a Mon Sep 17 00:00:00 2001 From: jkindly Date: Thu, 19 Sep 2024 13:21:14 +0200 Subject: [PATCH 3/8] OP-545: Behat fix --- .../assets/admin/js/cms/cms-content-configuration.js | 5 ++++- src/Resources/assets/admin/js/cms/cms-template.js | 9 +++++---- src/Resources/assets/admin/js/index.js | 2 +- src/Resources/config/routing/admin/template.yml | 2 +- src/Resources/views/ContentTemplate/form.html.twig | 2 +- tests/Behat/Page/Admin/Block/CreatePage.php | 4 ++-- tests/Behat/Page/Admin/Page/CreatePage.php | 4 ++-- 7 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/Resources/assets/admin/js/cms/cms-content-configuration.js b/src/Resources/assets/admin/js/cms/cms-content-configuration.js index 1320437a..a0754cca 100644 --- a/src/Resources/assets/admin/js/cms/cms-content-configuration.js +++ b/src/Resources/assets/admin/js/cms/cms-content-configuration.js @@ -110,7 +110,10 @@ $(document).ready(function() { const textareaId = `${collectionHolder}_${index}_configuration_textarea`; element.id = textareaId; - CKEDITOR.replace(textareaId, ckeditorConfig); + + if (typeof CKEDITOR !== 'undefined') { + CKEDITOR.replace(textareaId, ckeditorConfig); + } } }); } diff --git a/src/Resources/assets/admin/js/cms/cms-template.js b/src/Resources/assets/admin/js/cms/cms-template.js index 87d631dc..e2033b1e 100644 --- a/src/Resources/assets/admin/js/cms/cms-template.js +++ b/src/Resources/assets/admin/js/cms/cms-template.js @@ -1,9 +1,9 @@ export class HandleTemplate { init() { $(document).ready(() => { - const cmsLoadTemplate = $('[data-bb-cms-load-template]'); - const cmsPageTemplate = $('#sylius_cms_page_template'); - const cmsBlockTemplate = $('#sylius_cms_block_template'); + const cmsLoadTemplate = $('[data-bb-cms-load-content-template]'); + const cmsPageTemplate = $('#sylius_cms_page_contentTemplate'); + const cmsBlockTemplate = $('#sylius_cms_block_contentTemplate'); let locales = []; $('.locale-selector option').each(function() { @@ -28,7 +28,7 @@ export class HandleTemplate { return; } - const endpointUrl = cmsLoadTemplate.data('bb-cms-load-template').replace('REPLACE_ID', templateId); + const endpointUrl = cmsLoadTemplate.data('bb-cms-load-content-template').replace('REPLACE_ID', templateId); if (!endpointUrl) { return; } @@ -52,6 +52,7 @@ export class HandleTemplate { let idx = 0; $.each(data.content, function (index, element) { locales.forEach(function (locale) { + console.log(locale); elements.eq(idx).find('select:first').val(element.type); elements.eq(idx).find('select:first').change(); elements.eq(idx).find('input[name$="[locale]"]').val(locale); diff --git a/src/Resources/assets/admin/js/index.js b/src/Resources/assets/admin/js/index.js index a3587190..19cd8bf6 100644 --- a/src/Resources/assets/admin/js/index.js +++ b/src/Resources/assets/admin/js/index.js @@ -27,6 +27,6 @@ if (document.querySelector('.collection-type-items')) { new HandleChooseCollectionType().init(); } -if (document.querySelector('[data-bb-cms-load-template]')) { +if (document.querySelector('[data-bb-cms-load-content-template]')) { new HandleTemplate().init(); } diff --git a/src/Resources/config/routing/admin/template.yml b/src/Resources/config/routing/admin/template.yml index 33d2d8ad..9ce48ee6 100755 --- a/src/Resources/config/routing/admin/template.yml +++ b/src/Resources/config/routing/admin/template.yml @@ -10,7 +10,7 @@ sylius_cms_admin_template: vars: all: templates: - form: "@SyliusCmsPlugin/Template/Crud/_form.html.twig" + form: "@SyliusCmsPlugin/ContentTemplate/Crud/_form.html.twig" index: icon: block layout type: sylius.resource diff --git a/src/Resources/views/ContentTemplate/form.html.twig b/src/Resources/views/ContentTemplate/form.html.twig index 0b8d0e5d..6c15d012 100644 --- a/src/Resources/views/ContentTemplate/form.html.twig +++ b/src/Resources/views/ContentTemplate/form.html.twig @@ -3,7 +3,7 @@
{{ form_row(form.contentTemplate) }} - +
diff --git a/tests/Behat/Page/Admin/Block/CreatePage.php b/tests/Behat/Page/Admin/Block/CreatePage.php index 5098fdcf..23a6528f 100755 --- a/tests/Behat/Page/Admin/Block/CreatePage.php +++ b/tests/Behat/Page/Admin/Block/CreatePage.php @@ -300,8 +300,8 @@ protected function getDefinedElements(): array 'association_dropdown_collection' => '.field > label:contains("Collections") ~ .sylius-autocomplete', 'association_dropdown_collection_item' => '.field > label:contains("Collections") ~ .sylius-autocomplete > div.menu > div.item:contains("%item%")', 'content_elements_add_button' => '#sylius_cms_block_contentElements a[data-form-collection="add"]', - 'template_select_dropdown' => 'h5:contains("Use page template") ~ .column .field > .sylius-autocomplete', - 'template_select_dropdown_item' => 'h5:contains("Use page template") ~ .column .field > .sylius-autocomplete > div.menu > div.item:contains("%item%")', + 'template_select_dropdown' => 'h5:contains("Content elements template") ~ .column .field > .sylius-autocomplete', + 'template_select_dropdown_item' => 'h5:contains("Content elements template") ~ .column .field > .sylius-autocomplete > div.menu > div.item:contains("%item%")', ], ); } diff --git a/tests/Behat/Page/Admin/Page/CreatePage.php b/tests/Behat/Page/Admin/Page/CreatePage.php index 83f983cd..22580b85 100755 --- a/tests/Behat/Page/Admin/Page/CreatePage.php +++ b/tests/Behat/Page/Admin/Page/CreatePage.php @@ -310,8 +310,8 @@ protected function getDefinedElements(): array 'association_dropdown_collection' => '.field > label:contains("Collections") ~ .sylius-autocomplete', 'association_dropdown_collection_item' => '.field > label:contains("Collections") ~ .sylius-autocomplete > div.menu > div.item:contains("%item%")', 'content_elements_add_button' => '#sylius_cms_page_contentElements a[data-form-collection="add"]', - 'template_select_dropdown' => 'h5:contains("Use page template") ~ .column .field > .sylius-autocomplete', - 'template_select_dropdown_item' => 'h5:contains("Use page template") ~ .column .field > .sylius-autocomplete > div.menu > div.item:contains("%item%")', + 'template_select_dropdown' => 'h5:contains("Content elements template") ~ .column .field > .sylius-autocomplete', + 'template_select_dropdown_item' => 'h5:contains("Content elements template") ~ .column .field > .sylius-autocomplete > div.menu > div.item:contains("%item%")', ], ); } From a12fc54a56512a8ec1dd6c2c3c07ad2af217eaac Mon Sep 17 00:00:00 2001 From: jkindly Date: Fri, 20 Sep 2024 14:24:20 +0200 Subject: [PATCH 4/8] OP-545: Behat --- features/admin/adding_block.feature | 6 +- ...eature => adding_content_template.feature} | 2 +- features/admin/adding_page.feature | 21 ++++- ...ure => managing_content_templates.feature} | 2 +- features/admin/managing_pages.feature | 2 +- .../Provider/ResourceTemplateProviderSpec.php | 52 +++++++++++ .../Context/Setup/ContentTemplateContext.php | 86 ++++++++++++++++++ tests/Behat/Context/Setup/TemplateContext.php | 91 ++++++++----------- tests/Behat/Context/Ui/Admin/BlockContext.php | 6 +- ...Context.php => ContentTemplateContext.php} | 2 +- tests/Behat/Context/Ui/Admin/PageContext.php | 24 ++++- tests/Behat/Context/Ui/Shop/PageContext.php | 8 ++ tests/Behat/Page/Admin/Block/CreatePage.php | 12 +-- .../Page/Admin/Block/CreatePageInterface.php | 2 +- tests/Behat/Page/Admin/Page/CreatePage.php | 22 +++-- .../Page/Admin/Page/CreatePageInterface.php | 6 +- tests/Behat/Page/Shop/Page/ShowPage.php | 6 ++ .../Page/Shop/Page/ShowPageInterface.php | 2 + .../Resources/services/contexts/setup.xml | 4 +- .../Behat/Resources/services/contexts/ui.xml | 2 +- tests/Behat/Resources/suites.yml | 2 +- .../Resources/suites/ui/managing_blocks.yml | 2 +- ...tes.yml => managing_content_templates.yml} | 8 +- .../Resources/suites/ui/managing_pages.yml | 2 + 24 files changed, 278 insertions(+), 94 deletions(-) rename features/admin/{adding_template.feature => adding_content_template.feature} (98%) rename features/admin/{managing_templates.feature => managing_content_templates.feature} (98%) create mode 100644 spec/Provider/ResourceTemplateProviderSpec.php create mode 100644 tests/Behat/Context/Setup/ContentTemplateContext.php rename tests/Behat/Context/Ui/Admin/{TemplateContext.php => ContentTemplateContext.php} (99%) rename tests/Behat/Resources/suites/ui/{managing_templates.yml => managing_content_templates.yml} (50%) diff --git a/features/admin/adding_block.feature b/features/admin/adding_block.feature index c721508e..b7c72bb3 100644 --- a/features/admin/adding_block.feature +++ b/features/admin/adding_block.feature @@ -181,12 +181,12 @@ Feature: Adding blocks Then I should be notified that "Code, Name" fields are too long @ui @javascript - Scenario: Adding block with template - Given there is an existing template named "Homepage" with "Block" type that contains "Textarea, Single media" content elements + Scenario: Adding block with content template + Given there is an existing content template named "Homepage" with "Block" type that contains "Textarea, Single media" content elements When I go to the create block page And I fill the code with "intro" And I fill the name with "Intro" - And I select "Homepage" template + And I select "Homepage" content 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_template.feature b/features/admin/adding_content_template.feature similarity index 98% rename from features/admin/adding_template.feature rename to features/admin/adding_content_template.feature index 3197fb24..b6fdb411 100644 --- a/features/admin/adding_template.feature +++ b/features/admin/adding_content_template.feature @@ -1,4 +1,4 @@ -@managing_templates +@managing_content_templates Feature: Adding cms templates In order to create templates As an Administrator diff --git a/features/admin/adding_page.feature b/features/admin/adding_page.feature index 9f2881eb..552fe207 100644 --- a/features/admin/adding_page.feature +++ b/features/admin/adding_page.feature @@ -210,15 +210,30 @@ Feature: Adding new page And I should see newly created "Multiple media" content element in Content elements section @ui @javascript - Scenario: Adding page with template - Given there is an existing template named "Homepage" with "Page" type that contains "Textarea, Single media" content elements + Scenario: Adding page with content template + Given there is an existing content template named "Homepage" with "Page" type that contains "Textarea, Single media" content elements When I go to the create page page And I fill the code with "my_page" And I fill the slug with "my_page" And I fill the name with "My page" - And I select "Homepage" template + And I select "Homepage" content 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 And I should see newly created "Textarea" content element in Content elements section And I should see newly created "Single media" content element in Content elements section + + @ui @javascript + Scenario: Adding page with with a custom template + Given there is an existing template with "@SyliusCmsPlugin/Shop/Page/custom.html.twig" value + When I go to the create page page + And I fill the code with "my_page" + And I fill the slug with "my-page" + And I fill the name with "My page" + And I select "United States" channel + And I select "@SyliusCmsPlugin/Shop/Page/custom.html.twig" template + And I add it + Then I should be notified that the page has been created + And I go to the "my-page" page + And The rendered page should contain custom layout code + diff --git a/features/admin/managing_templates.feature b/features/admin/managing_content_templates.feature similarity index 98% rename from features/admin/managing_templates.feature rename to features/admin/managing_content_templates.feature index 0dd95fd9..7da7d5ae 100644 --- a/features/admin/managing_templates.feature +++ b/features/admin/managing_content_templates.feature @@ -1,4 +1,4 @@ -@managing_templates +@managing_content_templates Feature: Managing cms templates In order to manage existing templates As an Administrator diff --git a/features/admin/managing_pages.feature b/features/admin/managing_pages.feature index 27c73d3d..6e02852b 100644 --- a/features/admin/managing_pages.feature +++ b/features/admin/managing_pages.feature @@ -11,7 +11,7 @@ Feature: Managing cms pages @ui Scenario: Deleting page Given there is a page in the store - When I go to the pages page + When I go to the cms pages page And I delete this page Then I should be notified that the page has been deleted And I should see empty list of pages diff --git a/spec/Provider/ResourceTemplateProviderSpec.php b/spec/Provider/ResourceTemplateProviderSpec.php new file mode 100644 index 00000000..42660386 --- /dev/null +++ b/spec/Provider/ResourceTemplateProviderSpec.php @@ -0,0 +1,52 @@ +get('sylius_cms.templates.pages')->willReturn([ + '@CustomTemplate/Page.html.twig' => '@CustomTemplate/Page.html.twig', + ]); + + $parameterBag->get('sylius_cms.templates.blocks')->willReturn([ + '@CustomTemplate/Block.html.twig' => '@CustomTemplate/Block.html.twig', + ]); + + $this->beConstructedWith($parameterBag); + } + + public function it_is_initializable(): void + { + $this->shouldHaveType(ResourceTemplateProvider::class); + } + + public function it_implements_resource_template_provider_interface(): void + { + $this->shouldImplement(ResourceTemplateProviderInterface::class); + } + + public function it_returns_default_and_custom_page_templates(): void + { + $this->getPageTemplates()->shouldReturn([ + 'sylius.ui.default' => '@SyliusCmsPlugin/Shop/Page/show.html.twig', + '@CustomTemplate/Page.html.twig' => '@CustomTemplate/Page.html.twig', + ]); + } + + public function it_returns_default_and_custom_block_templates(): void + { + $this->getBlockTemplates()->shouldReturn([ + 'sylius.ui.default' => '@SyliusCmsPlugin/Shop/Block/show.html.twig', + '@CustomTemplate/Block.html.twig' => '@CustomTemplate/Block.html.twig', + ]); + } +} diff --git a/tests/Behat/Context/Setup/ContentTemplateContext.php b/tests/Behat/Context/Setup/ContentTemplateContext.php new file mode 100644 index 00000000..a86f23df --- /dev/null +++ b/tests/Behat/Context/Setup/ContentTemplateContext.php @@ -0,0 +1,86 @@ +createTemplate($name, $type); + + $this->saveTemplate($template); + } + + /** + * @Given there are :firstContentElement and :secondContentElement content elements in this template + */ + public function thereAreContentElementsInThisTemplate(string $firstContentElement, string $secondContentElement): void + { + /** @var TemplateInterface $template */ + $template = $this->sharedStorage->get('template'); + $template->setContentElements([ + ['type' => ContentElementHelper::getContentElementValueByName($firstContentElement)], + ['type' => ContentElementHelper::getContentElementValueByName($secondContentElement)], + ]); + + $this->saveTemplate($template); + } + + /** + * @Given there is an existing content template named :templateName with :type type that contains :contentElements content elements + */ + public function thereIsAnExistingTemplateThatContainsContentElements(string $templateName, string $type, string $contentElements): void + { + $template = $this->createTemplate($templateName, $type); + + $contentElements = explode(', ', $contentElements); + + $contentElementsArray = []; + foreach ($contentElements as $contentElement) { + $contentElementsArray[] = ['type' => ContentElementHelper::getContentElementValueByName($contentElement)]; + } + + $template->setContentElements($contentElementsArray); + + $this->saveTemplate($template); + } + + private function createTemplate(string $name, ?string $type = null): TemplateInterface + { + /** @var TemplateInterface $template */ + $template = $this->templateFactory->createNew(); + $template->setName($name); + + if (null !== $type) { + $template->setType($type); + } + + return $template; + } + + private function saveTemplate(TemplateInterface $template): void + { + $this->templateRepository->add($template); + $this->sharedStorage->set('template', $template); + } +} diff --git a/tests/Behat/Context/Setup/TemplateContext.php b/tests/Behat/Context/Setup/TemplateContext.php index 7ed942df..6198794c 100644 --- a/tests/Behat/Context/Setup/TemplateContext.php +++ b/tests/Behat/Context/Setup/TemplateContext.php @@ -5,82 +5,63 @@ namespace Tests\Sylius\CmsPlugin\Behat\Context\Setup; use Behat\Behat\Context\Context; -use Sylius\Behat\Service\SharedStorageInterface; -use Sylius\CmsPlugin\Entity\TemplateInterface; -use Sylius\CmsPlugin\Repository\TemplateRepositoryInterface; -use Sylius\Component\Resource\Factory\FactoryInterface; -use Tests\Sylius\CmsPlugin\Behat\Helpers\ContentElementHelper; +use Behat\Behat\Tester\Exception\PendingException; +use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\Yaml\Yaml; final class TemplateContext implements Context { - public function __construct( - private FactoryInterface $templateFactory, - private SharedStorageInterface $sharedStorage, - private TemplateRepositoryInterface $templateRepository, - ) { + private Filesystem $filesystem; + private $tempConfigFile; + private $tempTemplateFile; + + public function __construct() + { + $this->filesystem = new Filesystem(); } /** - * @Given there is a template in the store with :name name - * @Given there is a template in the store with :name name and :type type + * @Given there is an existing template with :template value */ - public function thereIsATemplate(string $name, ?string $type = null): void + public function thereIsAnExistingTemplateWithValue($template) { - $template = $this->createTemplate($name, $type); + $this->tempConfigFile = __DIR__ . '/../../../Application/config/packages/sylius_cms_test.yaml'; + $config = [ + 'sylius_cms' => [ + 'templates' => [ + 'pages' => [$template] + ], + ], + ]; + + $this->filesystem->dumpFile($this->tempConfigFile, Yaml::dump($config)); + + $this->tempTemplateFile = $this->getTemplateFilePath($template); + $dummyTemplateContent = "
This is a test template for: $template
"; - $this->saveTemplate($template); + $this->filesystem->dumpFile($this->tempTemplateFile, $dummyTemplateContent); } /** - * @Given there are :firstContentElement and :secondContentElement content elements in this template + * Get the real template file path from the given template name. */ - public function thereAreContentElementsInThisTemplate(string $firstContentElement, string $secondContentElement): void + private function getTemplateFilePath($template): string { - /** @var TemplateInterface $template */ - $template = $this->sharedStorage->get('template'); - $template->setContentElements([ - ['type' => ContentElementHelper::getContentElementValueByName($firstContentElement)], - ['type' => ContentElementHelper::getContentElementValueByName($secondContentElement)], - ]); - - $this->saveTemplate($template); + $templatePath = str_replace('@SyliusCmsPlugin', 'Application/templates/bundles/SyliusCmsPlugin', $template); + return __DIR__ . '/../../../' . $templatePath; } /** - * @Given there is an existing template named :templateName with :type type that contains :contentElements content elements + * @AfterScenario */ - public function thereIsAnExistingTemplateThatContainsContentElements(string $templateName, string $type, string $contentElements): void + public function cleanup(): void { - $template = $this->createTemplate($templateName, $type); - - $contentElements = explode(', ', $contentElements); - - $contentElementsArray = []; - foreach ($contentElements as $contentElement) { - $contentElementsArray[] = ['type' => ContentElementHelper::getContentElementValueByName($contentElement)]; + if ($this->tempConfigFile && file_exists($this->tempConfigFile)) { + $this->filesystem->remove($this->tempConfigFile); } - $template->setContentElements($contentElementsArray); - - $this->saveTemplate($template); - } - - private function createTemplate(string $name, ?string $type = null): TemplateInterface - { - /** @var TemplateInterface $template */ - $template = $this->templateFactory->createNew(); - $template->setName($name); - - if (null !== $type) { - $template->setType($type); + if ($this->tempTemplateFile && file_exists($this->tempTemplateFile)) { + $this->filesystem->remove($this->tempTemplateFile); } - - return $template; - } - - private function saveTemplate(TemplateInterface $template): void - { - $this->templateRepository->add($template); - $this->sharedStorage->set('template', $template); } } diff --git a/tests/Behat/Context/Ui/Admin/BlockContext.php b/tests/Behat/Context/Ui/Admin/BlockContext.php index 92224332..ddeebbcd 100755 --- a/tests/Behat/Context/Ui/Admin/BlockContext.php +++ b/tests/Behat/Context/Ui/Admin/BlockContext.php @@ -401,11 +401,11 @@ public function iShouldSeeEmptyListOfBlocks(): void } /** - * @Then I select :templateName template + * @Then I select :templateName content template */ - public function iSelectTemplate(string $templateName): void + public function iSelectContentTemplate(string $templateName): void { - $this->resolveCurrentPage()->selectTemplate($templateName); + $this->resolveCurrentPage()->selectContentTemplate($templateName); } /** diff --git a/tests/Behat/Context/Ui/Admin/TemplateContext.php b/tests/Behat/Context/Ui/Admin/ContentTemplateContext.php similarity index 99% rename from tests/Behat/Context/Ui/Admin/TemplateContext.php rename to tests/Behat/Context/Ui/Admin/ContentTemplateContext.php index 78939072..eb48faba 100644 --- a/tests/Behat/Context/Ui/Admin/TemplateContext.php +++ b/tests/Behat/Context/Ui/Admin/ContentTemplateContext.php @@ -17,7 +17,7 @@ use Tests\Sylius\CmsPlugin\Behat\Service\RandomStringGeneratorInterface; use Webmozart\Assert\Assert; -final class TemplateContext implements Context +final class ContentTemplateContext implements Context { public function __construct( private SharedStorageInterface $sharedStorage, diff --git a/tests/Behat/Context/Ui/Admin/PageContext.php b/tests/Behat/Context/Ui/Admin/PageContext.php index bf984a82..db966a1c 100755 --- a/tests/Behat/Context/Ui/Admin/PageContext.php +++ b/tests/Behat/Context/Ui/Admin/PageContext.php @@ -32,7 +32,7 @@ public function __construct( } /** - * @When I go to the pages page + * @When I go to the cms pages page */ public function iGoToTheCmsPagesPage(): void { @@ -99,6 +99,14 @@ public function iFillTheNameWith(string $name): void $this->resolveCurrentPage()->fillName($name); } + /** + * @When I select :code channel + */ + public function iSelectChannel(string $code): void + { + $this->resolveCurrentPage()->selectChannel($code); + } + /** * @When I fill the slug with :slug */ @@ -292,11 +300,11 @@ public function iShouldNotSeeContentElementInTheContentElementsSection(string $c } /** - * @Then I select :templateName template + * @Then I select :templateName content template */ - public function iSelectTemplate(string $templateName): void + public function iSelectContentTemplate(string $templateName): void { - $this->resolveCurrentPage()->selectTemplate($templateName); + $this->resolveCurrentPage()->selectContentTemplate($templateName); } /** @@ -307,6 +315,14 @@ public function iConfirmThatIWantToUseThisTemplate(): void $this->resolveCurrentPage()->confirmUseTemplate(); } + /** + * @Then I select :templateName template + */ + public function iSelectTemplate(string $templateName): void + { + $this->resolveCurrentPage()->selectTemplate($templateName); + } + /** * @When I add it * @When I try to add it diff --git a/tests/Behat/Context/Ui/Shop/PageContext.php b/tests/Behat/Context/Ui/Shop/PageContext.php index fa1898da..d8eabe35 100755 --- a/tests/Behat/Context/Ui/Shop/PageContext.php +++ b/tests/Behat/Context/Ui/Shop/PageContext.php @@ -108,4 +108,12 @@ public function iShouldSeePageTitle(string $title): void { Assert::true($this->showPage->hasTitle($title)); } + + /** + * @Then The rendered page should contain custom layout code + */ + public function theRenderedPageShouldContainCustomLayoutCode() + { + Assert::true($this->showPage->hasCustomLayoutCode()); + } } diff --git a/tests/Behat/Page/Admin/Block/CreatePage.php b/tests/Behat/Page/Admin/Block/CreatePage.php index 23a6528f..a3409322 100755 --- a/tests/Behat/Page/Admin/Block/CreatePage.php +++ b/tests/Behat/Page/Admin/Block/CreatePage.php @@ -265,18 +265,18 @@ public function addTaxonsListContentElementWithTaxons(array $taxons): void } } - public function selectTemplate(string $templateName): void + public function selectContentTemplate(string $templateName): void { - $dropdown = $this->getElement('template_select_dropdown'); + $dropdown = $this->getElement('content_template_select_dropdown'); $dropdown->click(); $dropdown->waitFor(5, function () use ($templateName): bool { - return $this->hasElement('template_select_dropdown_item', [ + return $this->hasElement('content_template_select_dropdown_item', [ '%item%' => $templateName, ]); }); - $item = $this->getElement('template_select_dropdown_item', [ + $item = $this->getElement('content_template_select_dropdown_item', [ '%item%' => $templateName, ]); @@ -300,8 +300,8 @@ protected function getDefinedElements(): array 'association_dropdown_collection' => '.field > label:contains("Collections") ~ .sylius-autocomplete', 'association_dropdown_collection_item' => '.field > label:contains("Collections") ~ .sylius-autocomplete > div.menu > div.item:contains("%item%")', 'content_elements_add_button' => '#sylius_cms_block_contentElements a[data-form-collection="add"]', - 'template_select_dropdown' => 'h5:contains("Content elements template") ~ .column .field > .sylius-autocomplete', - 'template_select_dropdown_item' => 'h5:contains("Content elements template") ~ .column .field > .sylius-autocomplete > div.menu > div.item:contains("%item%")', + 'content_template_select_dropdown' => 'h5:contains("Content elements template") ~ .column .field > .sylius-autocomplete', + 'content_template_select_dropdown_item' => 'h5:contains("Content elements template") ~ .column .field > .sylius-autocomplete > div.menu > div.item:contains("%item%")', ], ); } diff --git a/tests/Behat/Page/Admin/Block/CreatePageInterface.php b/tests/Behat/Page/Admin/Block/CreatePageInterface.php index 59644f53..ad5ed7db 100755 --- a/tests/Behat/Page/Admin/Block/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Block/CreatePageInterface.php @@ -47,7 +47,7 @@ public function addTaxonsListContentElementWithTaxons(array $taxons): void; public function disable(): void; - public function selectTemplate(string $templateName): void; + public function selectContentTemplate(string $templateName): void; public function confirmUseTemplate(): void; } diff --git a/tests/Behat/Page/Admin/Page/CreatePage.php b/tests/Behat/Page/Admin/Page/CreatePage.php index 22580b85..bf2ddaa6 100755 --- a/tests/Behat/Page/Admin/Page/CreatePage.php +++ b/tests/Behat/Page/Admin/Page/CreatePage.php @@ -274,18 +274,18 @@ public function addTaxonsListContentElementWithTaxons(array $taxons): void } } - public function selectTemplate(string $templateName): void + public function selectContentTemplate(string $templateName): void { - $dropdown = $this->getElement('template_select_dropdown'); + $dropdown = $this->getElement('content_template_select_dropdown'); $dropdown->click(); $dropdown->waitFor(5, function () use ($templateName): bool { - return $this->hasElement('template_select_dropdown_item', [ + return $this->hasElement('content_template_select_dropdown_item', [ '%item%' => $templateName, ]); }); - $item = $this->getElement('template_select_dropdown_item', [ + $item = $this->getElement('content_template_select_dropdown_item', [ '%item%' => $templateName, ]); @@ -300,6 +300,16 @@ public function confirmUseTemplate(): void }); } + public function selectTemplate(string $templateName): void + { + $this->getDocument()->selectFieldOption('Template', $templateName); + } + + public function selectChannel(string $code): void + { + $this->getDocument()->checkField($code); + } + protected function getDefinedElements(): array { return array_merge( @@ -310,8 +320,8 @@ protected function getDefinedElements(): array 'association_dropdown_collection' => '.field > label:contains("Collections") ~ .sylius-autocomplete', 'association_dropdown_collection_item' => '.field > label:contains("Collections") ~ .sylius-autocomplete > div.menu > div.item:contains("%item%")', 'content_elements_add_button' => '#sylius_cms_page_contentElements a[data-form-collection="add"]', - 'template_select_dropdown' => 'h5:contains("Content elements template") ~ .column .field > .sylius-autocomplete', - 'template_select_dropdown_item' => 'h5:contains("Content elements template") ~ .column .field > .sylius-autocomplete > div.menu > div.item:contains("%item%")', + 'content_template_select_dropdown' => 'h5:contains("Content elements template") ~ .column .field > .sylius-autocomplete', + 'content_template_select_dropdown_item' => 'h5:contains("Content elements template") ~ .column .field > .sylius-autocomplete > div.menu > div.item:contains("%item%")', ], ); } diff --git a/tests/Behat/Page/Admin/Page/CreatePageInterface.php b/tests/Behat/Page/Admin/Page/CreatePageInterface.php index 3b533859..912d14ca 100755 --- a/tests/Behat/Page/Admin/Page/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Page/CreatePageInterface.php @@ -51,7 +51,11 @@ public function addProductsGridByTaxonContentElementWithTaxon(string $taxon): vo public function addTaxonsListContentElementWithTaxons(array $taxons): void; - public function selectTemplate(string $templateName): void; + public function selectContentTemplate(string $templateName): void; public function confirmUseTemplate(): void; + + public function selectTemplate(string $templateName): void; + + public function selectChannel(string $code): void; } diff --git a/tests/Behat/Page/Shop/Page/ShowPage.php b/tests/Behat/Page/Shop/Page/ShowPage.php index d3a1ae9b..c3d44a3c 100755 --- a/tests/Behat/Page/Shop/Page/ShowPage.php +++ b/tests/Behat/Page/Shop/Page/ShowPage.php @@ -67,6 +67,11 @@ public function hasTitle(string $title): bool return $this->getSession()->evaluateScript('return document.title') === $title; } + public function hasCustomLayoutCode(): bool + { + return $this->hasElement('custom-layout'); + } + protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ @@ -76,6 +81,7 @@ protected function getDefinedElements(): array 'collections' => '.cms-page-collections', 'link' => '.cms-page-link', 'page-image' => '.page-image', + 'custom-layout' => '.custom-layout', ]); } } diff --git a/tests/Behat/Page/Shop/Page/ShowPageInterface.php b/tests/Behat/Page/Shop/Page/ShowPageInterface.php index 8da55940..00f69870 100755 --- a/tests/Behat/Page/Shop/Page/ShowPageInterface.php +++ b/tests/Behat/Page/Shop/Page/ShowPageInterface.php @@ -21,4 +21,6 @@ public function hasPageLink(string $linkName): bool; public function hasPageImage(): bool; public function hasTitle(string $title): bool; + + public function hasCustomLayoutCode(): bool; } diff --git a/tests/Behat/Resources/services/contexts/setup.xml b/tests/Behat/Resources/services/contexts/setup.xml index 57ffbf82..fda5d43e 100644 --- a/tests/Behat/Resources/services/contexts/setup.xml +++ b/tests/Behat/Resources/services/contexts/setup.xml @@ -37,10 +37,12 @@ - + + + diff --git a/tests/Behat/Resources/services/contexts/ui.xml b/tests/Behat/Resources/services/contexts/ui.xml index bde9105c..c575c9fe 100644 --- a/tests/Behat/Resources/services/contexts/ui.xml +++ b/tests/Behat/Resources/services/contexts/ui.xml @@ -60,7 +60,7 @@ - + diff --git a/tests/Behat/Resources/suites.yml b/tests/Behat/Resources/suites.yml index 8acb5a3f..865ba783 100644 --- a/tests/Behat/Resources/suites.yml +++ b/tests/Behat/Resources/suites.yml @@ -3,7 +3,7 @@ imports: - suites/ui/managing_pages.yml - suites/ui/managing_collections.yml - suites/ui/managing_media.yml - - suites/ui/managing_templates.yml + - suites/ui/managing_content_templates.yml - suites/ui/shop_blocks.yml - suites/ui/shop_media.yml - suites/ui/shop_pages.yml diff --git a/tests/Behat/Resources/suites/ui/managing_blocks.yml b/tests/Behat/Resources/suites/ui/managing_blocks.yml index 2b8060ab..ad82c741 100755 --- a/tests/Behat/Resources/suites/ui/managing_blocks.yml +++ b/tests/Behat/Resources/suites/ui/managing_blocks.yml @@ -11,7 +11,7 @@ default: - sylius_cms.behat.context.setup.block - sylius_cms.behat.context.setup.collection - sylius_cms.behat.context.setup.media - - sylius_cms.behat.context.setup.template + - sylius_cms.behat.context.setup.content_template - sylius_cms.behat.context.ui.admin.block filters: diff --git a/tests/Behat/Resources/suites/ui/managing_templates.yml b/tests/Behat/Resources/suites/ui/managing_content_templates.yml similarity index 50% rename from tests/Behat/Resources/suites/ui/managing_templates.yml rename to tests/Behat/Resources/suites/ui/managing_content_templates.yml index 9072486e..5538d7b8 100755 --- a/tests/Behat/Resources/suites/ui/managing_templates.yml +++ b/tests/Behat/Resources/suites/ui/managing_content_templates.yml @@ -1,11 +1,11 @@ default: suites: - ui_managing_templates: + ui_managing_content_templates: contexts: - sylius.behat.context.hook.doctrine_orm - sylius.behat.context.setup.channel - sylius.behat.context.setup.admin_security - - sylius_cms.behat.context.setup.template - - sylius_cms.behat.context.ui.admin.template + - sylius_cms.behat.context.setup.content_template + - sylius_cms.behat.context.ui.admin.content_template filters: - tags: "@managing_templates&&@ui" + tags: "@managing_content_templates&&@ui" diff --git a/tests/Behat/Resources/suites/ui/managing_pages.yml b/tests/Behat/Resources/suites/ui/managing_pages.yml index 349071ad..2c4bd190 100755 --- a/tests/Behat/Resources/suites/ui/managing_pages.yml +++ b/tests/Behat/Resources/suites/ui/managing_pages.yml @@ -11,8 +11,10 @@ default: - sylius_cms.behat.context.setup.media - sylius_cms.behat.context.setup.page - sylius_cms.behat.context.setup.collection + - sylius_cms.behat.context.setup.content_template - sylius_cms.behat.context.setup.template - sylius_cms.behat.context.ui.admin.page + - sylius_cms.behat.context.ui.shop.page filters: tags: "@managing_pages&&@ui" From d80f6590a9030a7467150048e8a81ce24bbae83d Mon Sep 17 00:00:00 2001 From: jkindly Date: Fri, 20 Sep 2024 14:25:06 +0200 Subject: [PATCH 5/8] OP-545: Behat TemplateContext.php --- tests/Behat/Context/Setup/TemplateContext.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/Behat/Context/Setup/TemplateContext.php b/tests/Behat/Context/Setup/TemplateContext.php index 6198794c..2416e3b7 100644 --- a/tests/Behat/Context/Setup/TemplateContext.php +++ b/tests/Behat/Context/Setup/TemplateContext.php @@ -5,15 +5,14 @@ namespace Tests\Sylius\CmsPlugin\Behat\Context\Setup; use Behat\Behat\Context\Context; -use Behat\Behat\Tester\Exception\PendingException; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Yaml\Yaml; final class TemplateContext implements Context { private Filesystem $filesystem; - private $tempConfigFile; - private $tempTemplateFile; + private string $tempConfigFile; + private string $tempTemplateFile; public function __construct() { @@ -23,7 +22,7 @@ public function __construct() /** * @Given there is an existing template with :template value */ - public function thereIsAnExistingTemplateWithValue($template) + public function thereIsAnExistingTemplateWithValue($template): void { $this->tempConfigFile = __DIR__ . '/../../../Application/config/packages/sylius_cms_test.yaml'; $config = [ From 41302f54811a1747f34019aa6e0790d3b0189e83 Mon Sep 17 00:00:00 2001 From: jkindly Date: Fri, 20 Sep 2024 14:27:17 +0200 Subject: [PATCH 6/8] OP-545: ECS --- tests/Behat/Context/Setup/TemplateContext.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/Behat/Context/Setup/TemplateContext.php b/tests/Behat/Context/Setup/TemplateContext.php index 2416e3b7..f2168afb 100644 --- a/tests/Behat/Context/Setup/TemplateContext.php +++ b/tests/Behat/Context/Setup/TemplateContext.php @@ -11,7 +11,9 @@ final class TemplateContext implements Context { private Filesystem $filesystem; + private string $tempConfigFile; + private string $tempTemplateFile; public function __construct() @@ -28,7 +30,7 @@ public function thereIsAnExistingTemplateWithValue($template): void $config = [ 'sylius_cms' => [ 'templates' => [ - 'pages' => [$template] + 'pages' => [$template], ], ], ]; @@ -47,6 +49,7 @@ public function thereIsAnExistingTemplateWithValue($template): void private function getTemplateFilePath($template): string { $templatePath = str_replace('@SyliusCmsPlugin', 'Application/templates/bundles/SyliusCmsPlugin', $template); + return __DIR__ . '/../../../' . $templatePath; } From e4399d51a16f3f835215145889b1abae0bf44e01 Mon Sep 17 00:00:00 2001 From: jkindly Date: Fri, 20 Sep 2024 14:33:48 +0200 Subject: [PATCH 7/8] OP-545: Behat fix --- tests/Behat/Context/Setup/TemplateContext.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Behat/Context/Setup/TemplateContext.php b/tests/Behat/Context/Setup/TemplateContext.php index f2168afb..fa8883b1 100644 --- a/tests/Behat/Context/Setup/TemplateContext.php +++ b/tests/Behat/Context/Setup/TemplateContext.php @@ -12,9 +12,9 @@ final class TemplateContext implements Context { private Filesystem $filesystem; - private string $tempConfigFile; + private string $tempConfigFile = ''; - private string $tempTemplateFile; + private string $tempTemplateFile = ''; public function __construct() { From b8e2cae96cf202f07f1e08816bf0664da55d789e Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 24 Sep 2024 08:45:14 +0200 Subject: [PATCH 8/8] OP-545: API --- .../serialization/ContentConfiguration.xml | 28 +++++++++++++++++++ .../config/serialization/PageTranslation.xml | 9 ++++++ .../DataFixtures/ORM/Api/PageTest/page.yml | 6 ++++ .../Api/PageTest/test_it_get_page_by_id.json | 5 +++- 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/Resources/config/serialization/ContentConfiguration.xml diff --git a/src/Resources/config/serialization/ContentConfiguration.xml b/src/Resources/config/serialization/ContentConfiguration.xml new file mode 100644 index 00000000..a288347f --- /dev/null +++ b/src/Resources/config/serialization/ContentConfiguration.xml @@ -0,0 +1,28 @@ + + + + + sylius_cms:page:read:index + sylius_cms:page:read:show + + + sylius_cms:page:read:index + sylius_cms:page:read:show + + + sylius_cms:page:read:show + + + sylius_cms:page:read:show + + + sylius_cms:page:read:show + + + sylius_cms:page:read:show + + + diff --git a/src/Resources/config/serialization/PageTranslation.xml b/src/Resources/config/serialization/PageTranslation.xml index 8d759d46..00b3e8f5 100644 --- a/src/Resources/config/serialization/PageTranslation.xml +++ b/src/Resources/config/serialization/PageTranslation.xml @@ -16,5 +16,14 @@ sylius_cms:page:read:show + + sylius_cms:page:read:show + + + sylius_cms:page:read:show + + + sylius_cms:page:read:show + diff --git a/tests/Functional/DataFixtures/ORM/Api/PageTest/page.yml b/tests/Functional/DataFixtures/ORM/Api/PageTest/page.yml index 1e4919a8..7501b1e7 100644 --- a/tests/Functional/DataFixtures/ORM/Api/PageTest/page.yml +++ b/tests/Functional/DataFixtures/ORM/Api/PageTest/page.yml @@ -78,16 +78,22 @@ Sylius\CmsPlugin\Entity\PageTranslation: slug: 'translation1_slug_en_US' metaKeywords: 'html,application' title: 'Amazing article1' + teaserTitle: "Amazing article1" + teaserContent: "This is a teaser content" page2_translation: locale: 'en_US' slug: 'translation2_slug_en_US' metaKeywords: 'html,application' title: 'Amazing article2' + teaserTitle: "Amazing article2" + teaserContent: "This is a teaser content" page3_translation: locale: 'en_US' slug: 'translation3_slug_en_US' metaKeywords: 'html,application' title: 'Amazing article3' + teaserTitle: "Amazing article3" + teaserContent: "This is a teaser content" Sylius\CmsPlugin\Entity\Page: page1: code: 'page1-code' diff --git a/tests/Functional/Responses/Expected/Api/PageTest/test_it_get_page_by_id.json b/tests/Functional/Responses/Expected/Api/PageTest/test_it_get_page_by_id.json index 5e08fe1e..b9fed7ff 100644 --- a/tests/Functional/Responses/Expected/Api/PageTest/test_it_get_page_by_id.json +++ b/tests/Functional/Responses/Expected/Api/PageTest/test_it_get_page_by_id.json @@ -13,7 +13,10 @@ "slug": "translation1_slug_en_US", "metaKeywords": "html,application", "metaDescription": null, - "title": "Amazing article1" + "title": "Amazing article1", + "teaserTitle": "Amazing article1", + "teaserContent": "This is a teaser content", + "teaserImage": null } } }