From ee7a3e4969826a7f8a9ec62689c0e54f3aef0083 Mon Sep 17 00:00:00 2001 From: jkindly Date: Fri, 21 Jun 2024 13:22:48 +0200 Subject: [PATCH 01/27] OP-321: Init update block functionality --- src/Entity/Block.php | 19 ++-- src/Entity/BlockContent.php | 57 +++++++++++ src/Entity/BlockContentAwareInterface.php | 26 +++++ src/Entity/BlockContentAwareTrait.php | 48 +++++++++ src/Entity/BlockContentInterface.php | 30 ++++++ src/Entity/BlockInterface.php | 3 +- src/Entity/BlockTranslation.php | 26 ----- src/Entity/BlockTranslationInterface.php | 8 -- .../BlockContentTextConfigurationType.php | 32 ++++++ src/Form/Type/BlockContentType.php | 98 +++++++++++++++++++ src/Form/Type/BlockType.php | 22 +++-- .../Type/Translation/BlockTranslationType.php | 8 -- src/Migrations/Version20240621093611.php | 37 +++++++ src/Repository/BlockContentRepository.php | 17 ++++ src/Resources/config/config.yml | 1 + src/Resources/config/doctrine/Block.orm.xml | 8 ++ .../config/doctrine/BlockContent.orm.xml | 26 +++++ .../config/doctrine/BlockTranslation.orm.xml | 6 +- src/Resources/config/resources.yml | 1 + .../config/resources/block_content.yml | 10 ++ src/Resources/config/serialization/Block.xml | 3 + .../config/serialization/BlockTranslation.xml | 6 -- .../config/serializer/Entity.Block.yml | 4 + src/Resources/config/services/form.xml | 17 ++++ .../config/validation/BlockTranslation.xml | 24 ----- .../views/Block/Crud/_form.html.twig | 30 +++--- 26 files changed, 453 insertions(+), 114 deletions(-) create mode 100644 src/Entity/BlockContent.php create mode 100644 src/Entity/BlockContentAwareInterface.php create mode 100644 src/Entity/BlockContentAwareTrait.php create mode 100644 src/Entity/BlockContentInterface.php create mode 100644 src/Form/Type/BlockContent/BlockContentTextConfigurationType.php create mode 100644 src/Form/Type/BlockContentType.php create mode 100644 src/Migrations/Version20240621093611.php create mode 100755 src/Repository/BlockContentRepository.php create mode 100644 src/Resources/config/doctrine/BlockContent.orm.xml create mode 100644 src/Resources/config/resources/block_content.yml diff --git a/src/Entity/Block.php b/src/Entity/Block.php index 277940816..f036a3de7 100755 --- a/src/Entity/Block.php +++ b/src/Entity/Block.php @@ -21,6 +21,7 @@ class Block implements BlockInterface use ProductsAwareTrait; use TaxonAwareTrait; use ChannelsAwareTrait; + use BlockContentAwareTrait; use TranslatableTrait { __construct as protected initializeTranslationsCollection; } @@ -32,13 +33,14 @@ public function __construct() $this->initializeProductsCollection(); $this->initializeTaxonCollection(); $this->initializeChannelsCollection(); + $this->initializeContentsCollection(); } - /** @var int|null */ - protected $id; + protected ?int $id; - /** @var string|null */ - protected $code; + protected ?string $code; + + protected ?string $name; public function getId(): ?int { @@ -57,17 +59,12 @@ public function setCode(?string $code): void public function getName(): ?string { - /** @var BlockTranslationInterface $blockTranslationInterface */ - $blockTranslationInterface = $this->getBlockTranslation(); - - return $blockTranslationInterface->getName(); + return $this->name; } public function setName(?string $name): void { - /** @var BlockTranslationInterface $blockTranslationInterface */ - $blockTranslationInterface = $this->getBlockTranslation(); - $blockTranslationInterface->setName($name); + $this->name = $name; } public function getContent(): ?string diff --git a/src/Entity/BlockContent.php b/src/Entity/BlockContent.php new file mode 100644 index 000000000..ec598425b --- /dev/null +++ b/src/Entity/BlockContent.php @@ -0,0 +1,57 @@ +id; + } + + public function getType(): ?string + { + return $this->type; + } + + public function setType(?string $type): void + { + $this->type = $type; + } + + public function getConfiguration(): array + { + return $this->configuration; + } + + public function setConfiguration(array $configuration): void + { + $this->configuration = $configuration; + } + + public function getBlock(): ?BlockInterface + { + return $this->block; + } + + public function setBlock(?BlockInterface $block): void + { + $this->block = $block; + } +} diff --git a/src/Entity/BlockContentAwareInterface.php b/src/Entity/BlockContentAwareInterface.php new file mode 100644 index 000000000..52cae0d5a --- /dev/null +++ b/src/Entity/BlockContentAwareInterface.php @@ -0,0 +1,26 @@ +contents = new ArrayCollection(); + } + + public function getContents(): Collection + { + return $this->contents; + } + + public function hasContent(BlockContentInterface $contentItem): bool + { + return $this->contents->contains($contentItem); + } + + public function addContent(BlockContentInterface $contentItem): void + { + if (!$this->hasContent($contentItem)) { + $this->contents->add($contentItem); + } + } + + public function removeContent(BlockContentInterface $contentItem): void + { + if ($this->hasContent($contentItem)) { + $this->contents->removeElement($contentItem); + } + } +} diff --git a/src/Entity/BlockContentInterface.php b/src/Entity/BlockContentInterface.php new file mode 100644 index 000000000..952e9552b --- /dev/null +++ b/src/Entity/BlockContentInterface.php @@ -0,0 +1,30 @@ +name; - } - - public function setName(?string $name): void - { - $this->name = $name; - } - public function getContent(): ?string { return $this->content; @@ -50,14 +34,4 @@ public function getId(): ?int { return $this->id; } - - public function getLink(): ?string - { - return $this->link; - } - - public function setLink(?string $link): void - { - $this->link = $link; - } } diff --git a/src/Entity/BlockTranslationInterface.php b/src/Entity/BlockTranslationInterface.php index 28676df90..d09dec2a8 100755 --- a/src/Entity/BlockTranslationInterface.php +++ b/src/Entity/BlockTranslationInterface.php @@ -15,15 +15,7 @@ interface BlockTranslationInterface extends ResourceInterface, TranslationInterface { - public function getName(): ?string; - - public function setName(?string $name): void; - public function getContent(): ?string; public function setContent(?string $content): void; - - public function getLink(): ?string; - - public function setLink(?string $link): void; } diff --git a/src/Form/Type/BlockContent/BlockContentTextConfigurationType.php b/src/Form/Type/BlockContent/BlockContentTextConfigurationType.php new file mode 100644 index 000000000..e721b5706 --- /dev/null +++ b/src/Form/Type/BlockContent/BlockContentTextConfigurationType.php @@ -0,0 +1,32 @@ +setDefaults([ + 'label' => 'bitbag_sylius_cms_plugin.ui.text', + ]); + } + + public function getParent(): string + { + return WysiwygType::class; + } +} diff --git a/src/Form/Type/BlockContentType.php b/src/Form/Type/BlockContentType.php new file mode 100644 index 000000000..140f8b479 --- /dev/null +++ b/src/Form/Type/BlockContentType.php @@ -0,0 +1,98 @@ + $formType) { + $this->actionConfigurationTypes[$type] = $formType::class; + $this->actionTypes['bitbag_sylius_cms_plugin.block_content.action.' . $type] = $type; + } + } + + public function buildForm(FormBuilderInterface $builder, array $options) + { + $defaultActionType = current($this->actionTypes); + $defaultActionConfigurationType = $this->actionConfigurationTypes[$defaultActionType]; + + $builder + ->add('type', ChoiceType::class, [ + 'label' => 'sylius.ui.type', + 'choices' => $this->actionTypes, + ]) + ->add('configuration', $defaultActionConfigurationType, [ + 'label' => false, + ]) + ; + + $builder + ->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event): void { + $this->addConfigurationTypeToForm($event); + }) + ->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event): void { + /** @var array|null $data */ + $data = $event->getData(); + if (null === $data) { + return; + } + + $form = $event->getForm(); + $formData = $form->getData(); + + if ($formData !== null && $formData->getType() !== $data['type']) { + $formData->setConfiguration([]); + } + + $this->addConfigurationTypeToForm($event); + }) + ; + } + + private function addConfigurationTypeToForm(FormEvent $event): void + { + $data = $event->getData(); + if ($data === null) { + return; + } + + $form = $event->getForm(); + + $dataType = $data instanceof CatalogPromotionActionInterface ? $data->getType() : $data['type']; + + $actionConfigurationType = $this->actionConfigurationTypes[$dataType]; + $form->add('configuration', $actionConfigurationType, [ + 'label' => false, + ]); + } + + public function getBlockPrefix(): string + { + return 'bitbag_sylius_cms_plugin_block_content'; + } +} diff --git a/src/Form/Type/BlockType.php b/src/Form/Type/BlockType.php index 5463527cd..5160d9997 100755 --- a/src/Form/Type/BlockType.php +++ b/src/Form/Type/BlockType.php @@ -13,14 +13,13 @@ use BitBag\SyliusCmsPlugin\Entity\BlockInterface; use BitBag\SyliusCmsPlugin\Form\Type\Translation\BlockTranslationType; use Sylius\Bundle\ChannelBundle\Form\Type\ChannelChoiceType; -use Sylius\Bundle\ProductBundle\Form\Type\ProductAutocompleteChoiceType; use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; use Sylius\Bundle\ResourceBundle\Form\Type\ResourceTranslationsType; -use Sylius\Bundle\TaxonomyBundle\Form\Type\TaxonAutocompleteChoiceType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Validator\Constraints\Valid; +use \Symfony\Component\Form\Extension\Core\Type\CollectionType as SymfonyCollectionType; final class BlockType extends AbstractResourceType { @@ -34,6 +33,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'label' => 'bitbag_sylius_cms_plugin.ui.code', 'disabled' => null !== $block->getCode(), ]) + ->add('name', TextType::class, [ + 'label' => 'bitbag_sylius_cms_plugin.ui.name', + ]) ->add('collections', CollectionAutocompleteChoiceType::class, [ 'label' => 'bitbag_sylius_cms_plugin.ui.collections', 'multiple' => true, @@ -41,20 +43,20 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('enabled', CheckboxType::class, [ 'label' => 'bitbag_sylius_cms_plugin.ui.enabled', ]) - ->add('products', ProductAutocompleteChoiceType::class, [ - 'label' => 'bitbag_sylius_cms_plugin.ui.products', - 'multiple' => true, - ]) - ->add('taxons', TaxonAutocompleteChoiceType::class, [ - 'label' => 'bitbag_sylius_cms_plugin.ui.taxons', - 'multiple' => true, - ]) ->add('channels', ChannelChoiceType::class, [ 'label' => 'bitbag_sylius_cms_plugin.ui.channels', 'required' => false, 'multiple' => true, 'expanded' => true, ]) + ->add('contents', SymfonyCollectionType::class, [ + 'label' => 'sylius.ui.actions', + 'entry_type' => BlockContentType::class, + 'allow_add' => true, + 'allow_delete' => true, + 'by_reference' => false, + 'required' => false, + ]) ->add('translations', ResourceTranslationsType::class, [ 'label' => 'bitbag_sylius_cms_plugin.ui.contents', 'entry_type' => BlockTranslationType::class, diff --git a/src/Form/Type/Translation/BlockTranslationType.php b/src/Form/Type/Translation/BlockTranslationType.php index 2c74b196c..7d54f09d5 100644 --- a/src/Form/Type/Translation/BlockTranslationType.php +++ b/src/Form/Type/Translation/BlockTranslationType.php @@ -20,14 +20,6 @@ final class BlockTranslationType extends AbstractResourceType public function buildForm(FormBuilderInterface $builder, array $options): void { $builder - ->add('name', TextType::class, [ - 'label' => 'bitbag_sylius_cms_plugin.ui.name', - 'required' => false, - ]) - ->add('link', TextType::class, [ - 'label' => 'bitbag_sylius_cms_plugin.ui.link', - 'required' => false, - ]) ->add('content', WysiwygType::class, [ 'required' => false, ]) diff --git a/src/Migrations/Version20240621093611.php b/src/Migrations/Version20240621093611.php new file mode 100644 index 000000000..8eab82fed --- /dev/null +++ b/src/Migrations/Version20240621093611.php @@ -0,0 +1,37 @@ +addSql('CREATE TABLE bitbag_cms_block_content (id INT AUTO_INCREMENT NOT NULL, block_id INT DEFAULT NULL, type VARCHAR(255) NOT NULL, configuration JSON NOT NULL COMMENT \'(DC2Type:json)\', INDEX IDX_FAA763A8E9ED820C (block_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('ALTER TABLE bitbag_cms_block_content ADD CONSTRAINT FK_FAA763A8E9ED820C FOREIGN KEY (block_id) REFERENCES bitbag_cms_block (id)'); + $this->addSql('ALTER TABLE bitbag_cms_block ADD name VARCHAR(250) DEFAULT NULL'); + $this->addSql('ALTER TABLE bitbag_cms_block_translation DROP name, DROP link'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE bitbag_cms_block_content DROP FOREIGN KEY FK_FAA763A8E9ED820C'); + $this->addSql('DROP TABLE bitbag_cms_block_content'); + $this->addSql('ALTER TABLE bitbag_cms_block_translation ADD name VARCHAR(255) DEFAULT NULL, ADD link LONGTEXT DEFAULT NULL'); + $this->addSql('ALTER TABLE bitbag_cms_block DROP name'); + } +} diff --git a/src/Repository/BlockContentRepository.php b/src/Repository/BlockContentRepository.php new file mode 100755 index 000000000..0e70df7c0 --- /dev/null +++ b/src/Repository/BlockContentRepository.php @@ -0,0 +1,17 @@ + + + @@ -58,5 +60,11 @@ + + + + + + diff --git a/src/Resources/config/doctrine/BlockContent.orm.xml b/src/Resources/config/doctrine/BlockContent.orm.xml new file mode 100644 index 000000000..b928a5afc --- /dev/null +++ b/src/Resources/config/doctrine/BlockContent.orm.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Resources/config/doctrine/BlockTranslation.orm.xml b/src/Resources/config/doctrine/BlockTranslation.orm.xml index b3ebfa897..f6ebc175a 100644 --- a/src/Resources/config/doctrine/BlockTranslation.orm.xml +++ b/src/Resources/config/doctrine/BlockTranslation.orm.xml @@ -10,10 +10,6 @@ - - - - - \ No newline at end of file + diff --git a/src/Resources/config/resources.yml b/src/Resources/config/resources.yml index df0a8c254..52b3c7564 100755 --- a/src/Resources/config/resources.yml +++ b/src/Resources/config/resources.yml @@ -1,5 +1,6 @@ imports: - { resource: resources/block.yml } + - { resource: resources/block_content.yml } - { resource: resources/page.yml } - { resource: resources/frequently_asked_question.yml } - { resource: resources/collection.yml } diff --git a/src/Resources/config/resources/block_content.yml b/src/Resources/config/resources/block_content.yml new file mode 100644 index 000000000..194fbe3f9 --- /dev/null +++ b/src/Resources/config/resources/block_content.yml @@ -0,0 +1,10 @@ +sylius_resource: + resources: + bitbag_sylius_cms_plugin.block_content: + driver: doctrine/orm + classes: + model: BitBag\SyliusCmsPlugin\Entity\BlockContent + interface: BitBag\SyliusCmsPlugin\Entity\BlockContentInterface + form: BitBag\SyliusCmsPlugin\Form\Type\BlockContentType + repository: BitBag\SyliusCmsPlugin\Repository\BlockContentRepository + factory: Sylius\Component\Resource\Factory\TranslatableFactory diff --git a/src/Resources/config/serialization/Block.xml b/src/Resources/config/serialization/Block.xml index 409b83860..7f41a675b 100644 --- a/src/Resources/config/serialization/Block.xml +++ b/src/Resources/config/serialization/Block.xml @@ -28,5 +28,8 @@ shop:cms:read + + shop:cms:read + diff --git a/src/Resources/config/serialization/BlockTranslation.xml b/src/Resources/config/serialization/BlockTranslation.xml index b56254f8c..10c34736c 100644 --- a/src/Resources/config/serialization/BlockTranslation.xml +++ b/src/Resources/config/serialization/BlockTranslation.xml @@ -4,14 +4,8 @@ xsi:schemaLocation="http://symfony.com/schema/dic/serializer-mapping https://symfony.com/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd" > - - shop:cms:read - shop:cms:read - - shop:cms:read - diff --git a/src/Resources/config/serializer/Entity.Block.yml b/src/Resources/config/serializer/Entity.Block.yml index 785a05373..0ddd253bf 100644 --- a/src/Resources/config/serializer/Entity.Block.yml +++ b/src/Resources/config/serializer/Entity.Block.yml @@ -11,6 +11,10 @@ BitBag\SyliusCmsPlugin\Entity\Block: expose: true type: string groups: [Autocomplete] + contents: + expose: true + type: iterable + groups: [Default] virtual_properties: getName: serialized_name: name diff --git a/src/Resources/config/services/form.xml b/src/Resources/config/services/form.xml index 87053c778..5c46b9591 100644 --- a/src/Resources/config/services/form.xml +++ b/src/Resources/config/services/form.xml @@ -1,6 +1,10 @@ + + BitBag\SyliusCmsPlugin\Form\Type\BlockContent\BlockContentTextConfigurationType::TYPE + + @@ -10,6 +14,13 @@ + + BitBag\SyliusCmsPlugin\Entity\BlockContent + %bitbag_sylius_cms_plugin.form.type.block_content.validation_groups% + + + + %bitbag_sylius_cms_plugin.model.block_translation.class% %bitbag_sylius_cms_plugin.form.type.translation.block.validation_groups% @@ -79,6 +90,12 @@ + + + + + + diff --git a/src/Resources/config/validation/BlockTranslation.xml b/src/Resources/config/validation/BlockTranslation.xml index bd3e547f1..61da5b5dd 100644 --- a/src/Resources/config/validation/BlockTranslation.xml +++ b/src/Resources/config/validation/BlockTranslation.xml @@ -4,30 +4,6 @@ http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd"> - - - - - - - - - - - - - - - - - - - - diff --git a/src/Resources/views/Block/Crud/_form.html.twig b/src/Resources/views/Block/Crud/_form.html.twig index 979e42571..f6ed4db1e 100755 --- a/src/Resources/views/Block/Crud/_form.html.twig +++ b/src/Resources/views/Block/Crud/_form.html.twig @@ -1,28 +1,28 @@ {% from '@BitBagSyliusCmsPlugin/Macro/translationForm.html.twig' import translationForm %} {% form_theme form '@BitBagSyliusCmsPlugin/Form/theme.html.twig' %} -{% include '@BitBagSyliusCmsPlugin/Modal/_resourcePreview.html.twig' %} - -
+
{{ form_errors(form) }} {{ form_row(form.code) }} + {{ form_row(form.name) }} {{ form_row(form.enabled) }} - {{ form_row(form.products) }} - {{ form_row(form.taxons) }} - {{ form_row(form.collections) }} {{ form_row(form.channels) }} + {{ form_row(form.collections) }} +
+
+
- - - {{ 'bitbag_sylius_cms_plugin.ui.preview'|trans }} - +
+
+
+

{{ 'sylius.ui.configuration'|trans }}

+
+
+ {{ form_row(form.contents) }} +
+
From ae0f0317200e270ff3ef832253190db39268ed5b Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 25 Jun 2024 13:04:48 +0200 Subject: [PATCH 02/27] OP-321: Update block functionality --- src/Controller/BlockController.php | 4 -- src/Entity/Block.php | 57 +------------------ src/Entity/BlockContent.php | 2 +- src/Entity/BlockContentAwareTrait.php | 2 + src/Entity/BlockInterface.php | 16 +----- src/Entity/BlockTranslation.php | 37 ------------ src/Entity/LocaleAwareInterface.php | 28 +++++++++ src/Entity/LocaleAwareTrait.php | 50 ++++++++++++++++ src/Fixture/BlockFixture.php | 13 ----- src/Fixture/Factory/BlockFixtureFactory.php | 45 --------------- .../BlockContentTextConfigurationType.php | 16 +++--- src/Form/Type/BlockContentType.php | 8 +-- src/Form/Type/BlockType.php | 16 ++---- .../Type/Translation/BlockTranslationType.php | 33 ----------- src/Importer/BlockImporter.php | 20 ------- src/Migrations/Version20240624122017.php | 57 +++++++++++++++++++ src/Repository/BlockRepository.php | 33 +---------- src/Repository/BlockRepositoryInterface.php | 11 +--- src/Resources/config/config.yml | 1 - src/Resources/config/doctrine/Block.orm.xml | 38 +++++-------- .../config/doctrine/BlockTranslation.orm.xml | 15 ----- src/Resources/config/grids/admin/block.yml | 3 - src/Resources/config/resources/block.yml | 6 +- src/Resources/config/routing/admin/block.yml | 1 - src/Resources/config/routing/shop/block.yml | 15 ----- .../config/serialization/BlockTranslation.xml | 11 ---- .../config/serializer/Entity.Block.yml | 4 -- src/Resources/config/services/fixture.xml | 6 -- src/Resources/config/services/form.xml | 12 +--- src/Resources/config/services/importer.xml | 1 - src/Resources/config/validation/Block.xml | 4 -- .../config/validation/BlockTranslation.xml | 17 ------ src/Resources/translations/messages.en.yml | 3 + .../views/Block/Crud/_form.html.twig | 13 ++--- 34 files changed, 190 insertions(+), 408 deletions(-) delete mode 100755 src/Entity/BlockTranslation.php create mode 100644 src/Entity/LocaleAwareInterface.php create mode 100644 src/Entity/LocaleAwareTrait.php delete mode 100644 src/Form/Type/Translation/BlockTranslationType.php create mode 100644 src/Migrations/Version20240624122017.php delete mode 100644 src/Resources/config/doctrine/BlockTranslation.orm.xml delete mode 100644 src/Resources/config/serialization/BlockTranslation.xml delete mode 100644 src/Resources/config/validation/BlockTranslation.xml diff --git a/src/Controller/BlockController.php b/src/Controller/BlockController.php index 32b77a1a8..c19a9e79a 100755 --- a/src/Controller/BlockController.php +++ b/src/Controller/BlockController.php @@ -69,10 +69,6 @@ public function previewAction(Request $request): Response /** @var BlockInterface $block */ $block = $form->getData(); - $defaultLocale = $this->getParameter('locale'); - - $block->setFallbackLocale($request->get('_locale', $defaultLocale)); - $block->setCurrentLocale($request->get('_locale', $defaultLocale)); if (!$configuration->isHtmlRequest()) { Assert::true(null !== $this->viewHandler); diff --git a/src/Entity/Block.php b/src/Entity/Block.php index f036a3de7..d03f63024 100755 --- a/src/Entity/Block.php +++ b/src/Entity/Block.php @@ -11,34 +11,26 @@ namespace BitBag\SyliusCmsPlugin\Entity; use Sylius\Component\Resource\Model\ToggleableTrait; -use Sylius\Component\Resource\Model\TranslatableTrait; -use Sylius\Component\Resource\Model\TranslationInterface; class Block implements BlockInterface { use ToggleableTrait; use CollectionableTrait; - use ProductsAwareTrait; - use TaxonAwareTrait; use ChannelsAwareTrait; use BlockContentAwareTrait; - use TranslatableTrait { - __construct as protected initializeTranslationsCollection; - } + use LocaleAwareTrait; public function __construct() { - $this->initializeTranslationsCollection(); $this->initializeCollectionsCollection(); - $this->initializeProductsCollection(); - $this->initializeTaxonCollection(); $this->initializeChannelsCollection(); $this->initializeContentsCollection(); + $this->initializeLocalesCollection(); } protected ?int $id; - protected ?string $code; + protected ?string $code = null; protected ?string $name; @@ -66,47 +58,4 @@ public function setName(?string $name): void { $this->name = $name; } - - public function getContent(): ?string - { - /** @var BlockTranslationInterface $blockTranslationInterface */ - $blockTranslationInterface = $this->getBlockTranslation(); - - return $blockTranslationInterface->getContent(); - } - - public function setContent(?string $content): void - { - /** @var BlockTranslationInterface $blockTranslationInterface */ - $blockTranslationInterface = $this->getBlockTranslation(); - $blockTranslationInterface->setContent($content); - } - - public function getLink(): ?string - { - /** @var BlockTranslationInterface $blockTranslationInterface */ - $blockTranslationInterface = $this->getBlockTranslation(); - - return $blockTranslationInterface->getLink(); - } - - public function setLink(?string $link): void - { - /** @var BlockTranslationInterface $blockTranslationInterface */ - $blockTranslationInterface = $this->getBlockTranslation(); - $blockTranslationInterface->setLink($link); - } - - /** - * @return BlockTranslationInterface|TranslationInterface - */ - protected function getBlockTranslation(): TranslationInterface - { - return $this->getTranslation(); - } - - protected function createTranslation(): BlockTranslationInterface - { - return new BlockTranslation(); - } } diff --git a/src/Entity/BlockContent.php b/src/Entity/BlockContent.php index ec598425b..b0db2f7b8 100644 --- a/src/Entity/BlockContent.php +++ b/src/Entity/BlockContent.php @@ -18,7 +18,7 @@ final class BlockContent implements BlockContentInterface protected array $configuration = []; - protected ?BlockInterface $block; + protected ?BlockInterface $block = null; public function getId(): ?int { diff --git a/src/Entity/BlockContentAwareTrait.php b/src/Entity/BlockContentAwareTrait.php index c7044f819..62eca144f 100644 --- a/src/Entity/BlockContentAwareTrait.php +++ b/src/Entity/BlockContentAwareTrait.php @@ -35,6 +35,7 @@ public function hasContent(BlockContentInterface $contentItem): bool public function addContent(BlockContentInterface $contentItem): void { if (!$this->hasContent($contentItem)) { + $contentItem->setBlock($this); $this->contents->add($contentItem); } } @@ -43,6 +44,7 @@ public function removeContent(BlockContentInterface $contentItem): void { if ($this->hasContent($contentItem)) { $this->contents->removeElement($contentItem); + $contentItem->setBlock(null); } } } diff --git a/src/Entity/BlockInterface.php b/src/Entity/BlockInterface.php index 8759ad91a..562cc76bb 100755 --- a/src/Entity/BlockInterface.php +++ b/src/Entity/BlockInterface.php @@ -13,18 +13,14 @@ use Sylius\Component\Channel\Model\ChannelsAwareInterface; use Sylius\Component\Resource\Model\ResourceInterface; use Sylius\Component\Resource\Model\ToggleableInterface; -use Sylius\Component\Resource\Model\TranslatableInterface; interface BlockInterface extends ResourceInterface, - TranslatableInterface, ToggleableInterface, - ProductsAwareInterface, - TaxonAwareInterface, CollectionableInterface, ChannelsAwareInterface, - ContentableInterface, - BlockContentAwareInterface + BlockContentAwareInterface, + LocaleAwareInterface { public function getCode(): ?string; @@ -33,12 +29,4 @@ public function setCode(?string $code): void; public function getName(): ?string; public function setName(?string $name): void; - - public function getContent(): ?string; - - public function setContent(?string $content): void; - - public function getLink(): ?string; - - public function setLink(?string $link): void; } diff --git a/src/Entity/BlockTranslation.php b/src/Entity/BlockTranslation.php deleted file mode 100755 index 68d877df8..000000000 --- a/src/Entity/BlockTranslation.php +++ /dev/null @@ -1,37 +0,0 @@ -content; - } - - public function setContent(?string $content): void - { - $this->content = $content; - } - - public function getId(): ?int - { - return $this->id; - } -} diff --git a/src/Entity/LocaleAwareInterface.php b/src/Entity/LocaleAwareInterface.php new file mode 100644 index 000000000..80d4aeefe --- /dev/null +++ b/src/Entity/LocaleAwareInterface.php @@ -0,0 +1,28 @@ +locales = new ArrayCollection(); + } + + public function getLocales(): Collection + { + return $this->locales; + } + + public function hasLocale(LocaleInterface $locale): bool + { + return $this->locales->contains($locale); + } + + public function addLocale(LocaleInterface $locale): void + { + if (!$this->hasLocale($locale)) { + $this->locales->add($locale); + } + } + + public function removeLocale(LocaleInterface $locale): void + { + if ($this->hasLocale($locale)) { + $this->locales->removeElement($locale); + } + } +} diff --git a/src/Fixture/BlockFixture.php b/src/Fixture/BlockFixture.php index 2a87c0f8c..2613dcdf8 100755 --- a/src/Fixture/BlockFixture.php +++ b/src/Fixture/BlockFixture.php @@ -41,21 +41,8 @@ protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void ->integerNode('number')->defaultNull()->end() ->booleanNode('last_four_products')->defaultFalse()->end() ->booleanNode('enabled')->defaultTrue()->end() - ->integerNode('products')->defaultNull()->end() - ->arrayNode('productCodes')->scalarPrototype()->end()->end() - ->arrayNode('taxons')->scalarPrototype()->end()->end() ->arrayNode('collections')->scalarPrototype()->end()->end() ->arrayNode('channels')->scalarPrototype()->end()->end() - ->arrayNode('translations') - ->arrayPrototype() - ->children() - ->scalarNode('name')->defaultNull()->end() - ->scalarNode('content')->defaultNull()->end() - ->scalarNode('link')->defaultNull()->end() - ->scalarNode('image_path')->defaultNull()->end() - ->end() - ->end() - ->end() ->end() ->end() ->end() diff --git a/src/Fixture/Factory/BlockFixtureFactory.php b/src/Fixture/Factory/BlockFixtureFactory.php index e4d6a6478..157bf2627 100755 --- a/src/Fixture/Factory/BlockFixtureFactory.php +++ b/src/Fixture/Factory/BlockFixtureFactory.php @@ -12,28 +12,15 @@ use BitBag\SyliusCmsPlugin\Assigner\ChannelsAssignerInterface; use BitBag\SyliusCmsPlugin\Assigner\CollectionsAssignerInterface; -use BitBag\SyliusCmsPlugin\Assigner\ProductsAssignerInterface; -use BitBag\SyliusCmsPlugin\Assigner\TaxonsAssignerInterface; use BitBag\SyliusCmsPlugin\Entity\BlockInterface; -use BitBag\SyliusCmsPlugin\Entity\BlockTranslationInterface; use BitBag\SyliusCmsPlugin\Repository\BlockRepositoryInterface; -use Sylius\Component\Channel\Context\ChannelContextInterface; -use Sylius\Component\Core\Model\ChannelInterface; -use Sylius\Component\Core\Repository\ProductRepositoryInterface; -use Sylius\Component\Locale\Context\LocaleContextInterface; use Sylius\Component\Resource\Factory\FactoryInterface; final class BlockFixtureFactory implements FixtureFactoryInterface { public function __construct( private FactoryInterface $blockFactory, - private FactoryInterface $blockTranslationFactory, private BlockRepositoryInterface $blockRepository, - private ProductRepositoryInterface $productRepository, - private ChannelContextInterface $channelContext, - private LocaleContextInterface $localeContext, - private ProductsAssignerInterface $productsAssigner, - private TaxonsAssignerInterface $taxonsAssigner, private CollectionsAssignerInterface $collectionsAssigner, private ChannelsAssignerInterface $channelAssigner, ) { @@ -66,44 +53,12 @@ private function createBlock(string $code, array $blockData): void /** @var BlockInterface $block */ $block = $this->blockFactory->createNew(); - $products = $blockData['products']; - if (null !== $products) { - $this->resolveProducts($block, $products); - } - $this->collectionsAssigner->assign($block, $blockData['collections']); - $this->productsAssigner->assign($block, $blockData['productCodes']); - $this->taxonsAssigner->assign($block, $blockData['taxons']); $this->channelAssigner->assign($block, $blockData['channels']); $block->setCode($code); $block->setEnabled($blockData['enabled']); - foreach ($blockData['translations'] as $localeCode => $translation) { - /** @var BlockTranslationInterface $blockTranslation */ - $blockTranslation = $this->blockTranslationFactory->createNew(); - - $blockTranslation->setLocale($localeCode); - $blockTranslation->setName($translation['name']); - $blockTranslation->setContent($translation['content']); - $blockTranslation->setLink($translation['link']); - $block->addTranslation($blockTranslation); - } - $this->blockRepository->add($block); } - - private function resolveProducts(BlockInterface $block, int $limit): void - { - /** @var ChannelInterface $channel */ - $channel = $this->channelContext->getChannel(); - $products = $this->productRepository->findLatestByChannel( - $channel, - $this->localeContext->getLocaleCode(), - $limit, - ); - foreach ($products as $product) { - $block->addProduct($product); - } - } } diff --git a/src/Form/Type/BlockContent/BlockContentTextConfigurationType.php b/src/Form/Type/BlockContent/BlockContentTextConfigurationType.php index e721b5706..d888eadcf 100644 --- a/src/Form/Type/BlockContent/BlockContentTextConfigurationType.php +++ b/src/Form/Type/BlockContent/BlockContentTextConfigurationType.php @@ -12,21 +12,23 @@ use BitBag\SyliusCmsPlugin\Form\Type\WysiwygType; use Symfony\Component\Form\AbstractType; -use Symfony\Component\OptionsResolver\OptionsResolver; +use Symfony\Component\Form\FormBuilderInterface; final class BlockContentTextConfigurationType extends AbstractType { public const TYPE = 'content_text'; - public function configureOptions(OptionsResolver $resolver): void + public function buildForm(FormBuilderInterface $builder, array $options): void { - $resolver->setDefaults([ - 'label' => 'bitbag_sylius_cms_plugin.ui.text', - ]); + $builder + ->add(self::TYPE, WysiwygType::class, [ + 'label' => 'bitbag_sylius_cms_plugin.ui.block_content.type.content_text', + ]) + ; } - public function getParent(): string + public function getBlockPrefix(): string { - return WysiwygType::class; + return 'bitbag_sylius_cms_plugin_block_content_text_configuration'; } } diff --git a/src/Form/Type/BlockContentType.php b/src/Form/Type/BlockContentType.php index 140f8b479..c4296b1c2 100644 --- a/src/Form/Type/BlockContentType.php +++ b/src/Form/Type/BlockContentType.php @@ -10,8 +10,8 @@ namespace BitBag\SyliusCmsPlugin\Form\Type; +use BitBag\SyliusCmsPlugin\Entity\BlockContentInterface; use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; -use Sylius\Component\Promotion\Model\CatalogPromotionActionInterface; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormEvent; @@ -32,11 +32,11 @@ public function __construct( foreach ($actionConfigurationTypes as $type => $formType) { $this->actionConfigurationTypes[$type] = $formType::class; - $this->actionTypes['bitbag_sylius_cms_plugin.block_content.action.' . $type] = $type; + $this->actionTypes['bitbag_sylius_cms_plugin.ui.block_content.type.' . $type] = $type; } } - public function buildForm(FormBuilderInterface $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options): void { $defaultActionType = current($this->actionTypes); $defaultActionConfigurationType = $this->actionConfigurationTypes[$defaultActionType]; @@ -83,7 +83,7 @@ private function addConfigurationTypeToForm(FormEvent $event): void $form = $event->getForm(); - $dataType = $data instanceof CatalogPromotionActionInterface ? $data->getType() : $data['type']; + $dataType = $data instanceof BlockContentInterface ? $data->getType() : $data['type']; $actionConfigurationType = $this->actionConfigurationTypes[$dataType]; $form->add('configuration', $actionConfigurationType, [ diff --git a/src/Form/Type/BlockType.php b/src/Form/Type/BlockType.php index 5160d9997..b723c9a7d 100755 --- a/src/Form/Type/BlockType.php +++ b/src/Form/Type/BlockType.php @@ -11,15 +11,12 @@ namespace BitBag\SyliusCmsPlugin\Form\Type; use BitBag\SyliusCmsPlugin\Entity\BlockInterface; -use BitBag\SyliusCmsPlugin\Form\Type\Translation\BlockTranslationType; use Sylius\Bundle\ChannelBundle\Form\Type\ChannelChoiceType; use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; -use Sylius\Bundle\ResourceBundle\Form\Type\ResourceTranslationsType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\Validator\Constraints\Valid; -use \Symfony\Component\Form\Extension\Core\Type\CollectionType as SymfonyCollectionType; +use Symfony\Component\Form\Extension\Core\Type\CollectionType; final class BlockType extends AbstractResourceType { @@ -49,20 +46,15 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'multiple' => true, 'expanded' => true, ]) - ->add('contents', SymfonyCollectionType::class, [ - 'label' => 'sylius.ui.actions', + ->add('locales') + ->add('contents', CollectionType::class, [ + 'label' => false, 'entry_type' => BlockContentType::class, 'allow_add' => true, 'allow_delete' => true, 'by_reference' => false, 'required' => false, ]) - ->add('translations', ResourceTranslationsType::class, [ - 'label' => 'bitbag_sylius_cms_plugin.ui.contents', - 'entry_type' => BlockTranslationType::class, - 'validation_groups' => ['bitbag_content'], - 'constraints' => [new Valid()], - ]) ; } diff --git a/src/Form/Type/Translation/BlockTranslationType.php b/src/Form/Type/Translation/BlockTranslationType.php deleted file mode 100644 index 7d54f09d5..000000000 --- a/src/Form/Type/Translation/BlockTranslationType.php +++ /dev/null @@ -1,33 +0,0 @@ -add('content', WysiwygType::class, [ - 'required' => false, - ]) - ; - } - - public function getBlockPrefix(): string - { - return 'bitbag_sylius_cms_plugin_text_translation'; - } -} diff --git a/src/Importer/BlockImporter.php b/src/Importer/BlockImporter.php index 589785cb4..d483de097 100644 --- a/src/Importer/BlockImporter.php +++ b/src/Importer/BlockImporter.php @@ -16,7 +16,6 @@ use BitBag\SyliusCmsPlugin\Resolver\ImporterCollectionsResolverInterface; use BitBag\SyliusCmsPlugin\Resolver\ImporterProductsResolverInterface; use BitBag\SyliusCmsPlugin\Resolver\ResourceResolverInterface; -use Sylius\Component\Locale\Context\LocaleContextInterface; use Symfony\Component\Validator\Validator\ValidatorInterface; use Webmozart\Assert\Assert; @@ -24,7 +23,6 @@ final class BlockImporter extends AbstractImporter implements BlockImporterInter { public function __construct( private ResourceResolverInterface $blockResourceResolver, - private LocaleContextInterface $localeContext, private ImporterCollectionsResolverInterface $importerCollectionsResolver, private ImporterChannelsResolverInterface $importerChannelsResolver, private ImporterProductsResolverInterface $importerProductsResolver, @@ -41,16 +39,7 @@ public function import(array $row): void Assert::notNull($code); /** @var BlockInterface $block */ $block = $this->blockResourceResolver->getResource($code); - $block->setCode($code); - $block->setFallbackLocale($this->localeContext->getLocaleCode()); - - foreach ($this->getAvailableLocales($this->getTranslatableColumns(), array_keys($row)) as $locale) { - $block->setCurrentLocale($locale); - $block->setName($this->getTranslatableColumnValue(self::NAME_COLUMN, $locale, $row)); - $block->setLink($this->getTranslatableColumnValue(self::LINK_COLUMN, $locale, $row)); - $block->setContent($this->getTranslatableColumnValue(self::CONTENT_COLUMN, $locale, $row)); - } $this->importerCollectionsResolver->resolve($block, $this->getColumnValue(self::COLLECTIONS_COLUMN, $row)); $this->importerChannelsResolver->resolve($block, $this->getColumnValue(self::CHANNELS_COLUMN, $row)); @@ -64,13 +53,4 @@ public function getResourceCode(): string { return 'block'; } - - private function getTranslatableColumns(): array - { - return [ - self::NAME_COLUMN, - self::CONTENT_COLUMN, - self::LINK_COLUMN, - ]; - } } diff --git a/src/Migrations/Version20240624122017.php b/src/Migrations/Version20240624122017.php new file mode 100644 index 000000000..29386e171 --- /dev/null +++ b/src/Migrations/Version20240624122017.php @@ -0,0 +1,57 @@ +addSql('CREATE TABLE bitbag_cms_block_locales (block_id INT NOT NULL, locale_id INT NOT NULL, INDEX IDX_E1F907BAE9ED820C (block_id), INDEX IDX_E1F907BAE559DFD1 (locale_id), PRIMARY KEY(block_id, locale_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE bitbag_cms_block_content (id INT AUTO_INCREMENT NOT NULL, block_id INT DEFAULT NULL, type VARCHAR(255) NOT NULL, configuration JSON NOT NULL COMMENT \'(DC2Type:json)\', INDEX IDX_FAA763A8E9ED820C (block_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('ALTER TABLE bitbag_cms_block_locales ADD CONSTRAINT FK_E1F907BAE9ED820C FOREIGN KEY (block_id) REFERENCES bitbag_cms_block (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE bitbag_cms_block_locales ADD CONSTRAINT FK_E1F907BAE559DFD1 FOREIGN KEY (locale_id) REFERENCES sylius_locale (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE bitbag_cms_block_content ADD CONSTRAINT FK_FAA763A8E9ED820C FOREIGN KEY (block_id) REFERENCES bitbag_cms_block (id)'); + $this->addSql('ALTER TABLE bitbag_cms_block_products DROP FOREIGN KEY FK_C4B9089F4584665A'); + $this->addSql('ALTER TABLE bitbag_cms_block_products DROP FOREIGN KEY FK_C4B9089FE9ED820C'); + $this->addSql('ALTER TABLE bitbag_cms_block_taxonomies DROP FOREIGN KEY FK_10C3E429E9ED820C'); + $this->addSql('ALTER TABLE bitbag_cms_block_taxonomies DROP FOREIGN KEY FK_10C3E429DE13F470'); + $this->addSql('ALTER TABLE bitbag_cms_block_translation DROP FOREIGN KEY FK_32897FDF2C2AC5D3'); + $this->addSql('DROP TABLE bitbag_cms_block_products'); + $this->addSql('DROP TABLE bitbag_cms_block_taxonomies'); + $this->addSql('DROP TABLE bitbag_cms_block_translation'); + $this->addSql('ALTER TABLE bitbag_cms_block ADD name VARCHAR(250) DEFAULT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('CREATE TABLE bitbag_cms_block_products (block_id INT NOT NULL, product_id INT NOT NULL, INDEX IDX_C4B9089FE9ED820C (block_id), INDEX IDX_C4B9089F4584665A (product_id), PRIMARY KEY(block_id, product_id)) DEFAULT CHARACTER SET utf8mb3 COLLATE `utf8mb3_unicode_ci` ENGINE = InnoDB COMMENT = \'\' '); + $this->addSql('CREATE TABLE bitbag_cms_block_taxonomies (block_id INT NOT NULL, taxon_id INT NOT NULL, INDEX IDX_10C3E429E9ED820C (block_id), INDEX IDX_10C3E429DE13F470 (taxon_id), PRIMARY KEY(block_id, taxon_id)) DEFAULT CHARACTER SET utf8mb3 COLLATE `utf8mb3_unicode_ci` ENGINE = InnoDB COMMENT = \'\' '); + $this->addSql('CREATE TABLE bitbag_cms_block_translation (id INT AUTO_INCREMENT NOT NULL, translatable_id INT NOT NULL, content LONGTEXT CHARACTER SET utf8mb3 DEFAULT NULL COLLATE `utf8mb3_unicode_ci`, locale VARCHAR(255) CHARACTER SET utf8mb3 NOT NULL COLLATE `utf8mb3_unicode_ci`, name VARCHAR(255) CHARACTER SET utf8mb3 DEFAULT NULL COLLATE `utf8mb3_unicode_ci`, link LONGTEXT CHARACTER SET utf8mb3 DEFAULT NULL COLLATE `utf8mb3_unicode_ci`, INDEX IDX_32897FDF2C2AC5D3 (translatable_id), UNIQUE INDEX bitbag_cms_block_translation_uniq_trans (translatable_id, locale), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb3 COLLATE `utf8mb3_unicode_ci` ENGINE = InnoDB COMMENT = \'\' '); + $this->addSql('ALTER TABLE bitbag_cms_block_products ADD CONSTRAINT FK_C4B9089F4584665A FOREIGN KEY (product_id) REFERENCES sylius_product (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE bitbag_cms_block_products ADD CONSTRAINT FK_C4B9089FE9ED820C FOREIGN KEY (block_id) REFERENCES bitbag_cms_block (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE bitbag_cms_block_taxonomies ADD CONSTRAINT FK_10C3E429E9ED820C FOREIGN KEY (block_id) REFERENCES bitbag_cms_block (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE bitbag_cms_block_taxonomies ADD CONSTRAINT FK_10C3E429DE13F470 FOREIGN KEY (taxon_id) REFERENCES sylius_taxon (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE bitbag_cms_block_translation ADD CONSTRAINT FK_32897FDF2C2AC5D3 FOREIGN KEY (translatable_id) REFERENCES bitbag_cms_block (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE bitbag_cms_block_locales DROP FOREIGN KEY FK_E1F907BAE9ED820C'); + $this->addSql('ALTER TABLE bitbag_cms_block_locales DROP FOREIGN KEY FK_E1F907BAE559DFD1'); + $this->addSql('ALTER TABLE bitbag_cms_block_content DROP FOREIGN KEY FK_FAA763A8E9ED820C'); + $this->addSql('DROP TABLE bitbag_cms_block_locales'); + $this->addSql('DROP TABLE bitbag_cms_block_content'); + $this->addSql('ALTER TABLE bitbag_cms_block DROP name'); + } +} diff --git a/src/Repository/BlockRepository.php b/src/Repository/BlockRepository.php index 4d32cc427..f6b7e71a1 100755 --- a/src/Repository/BlockRepository.php +++ b/src/Repository/BlockRepository.php @@ -16,8 +16,6 @@ class BlockRepository extends EntityRepository implements BlockRepositoryInterface { - use TranslationBasedAwareTrait; - public function createListQueryBuilder(string $localeCode): QueryBuilder { return $this->createQueryBuilder('o') @@ -43,18 +41,14 @@ public function findEnabledByCode(string $code, string $channelCode): ?BlockInte public function findByCollectionCode( string $collectionCode, - string $localeCode, string $channelCode, ): array { return $this->createQueryBuilder('o') - ->leftJoin('o.translations', 'translation') ->innerJoin('o.collections', 'collection') ->innerJoin('o.channels', 'channels') - ->andWhere('translation.locale = :localeCode') ->andWhere('collection.code = :collectionCode') ->andWhere('o.enabled = true') ->andWhere('channels.code = :channelCode') - ->setParameter('localeCode', $localeCode) ->setParameter('collectionCode', $collectionCode) ->setParameter('channelCode', $channelCode) ->getQuery() @@ -62,31 +56,10 @@ public function findByCollectionCode( ; } - public function findByProductCode( - string $productCode, - string $localeCode, - string $channelCode, - ): array { - return $this->createQueryBuilder('o') - ->leftJoin('o.translations', 'translation') - ->innerJoin('o.products', 'product') - ->innerJoin('o.channels', 'channels') - ->andWhere('translation.locale = :localeCode') - ->andWhere('product.code = :productCode') - ->andWhere('o.enabled = true') - ->andWhere('channels.code = :channelCode') - ->setParameter('localeCode', $localeCode) - ->setParameter('productCode', $productCode) - ->setParameter('channelCode', $channelCode) - ->getQuery() - ->getResult() - ; - } - - public function findByNamePart(string $phrase, ?string $locale = null): array + public function findByNamePart(string $phrase): array { - return $this->createTranslationBasedQueryBuilder($locale) - ->andWhere('translation.name LIKE :name') + return $this->createQueryBuilder('o') + ->andWhere('o.name LIKE :name') ->setParameter('name', '%' . $phrase . '%') ->getQuery() ->getResult() diff --git a/src/Repository/BlockRepositoryInterface.php b/src/Repository/BlockRepositoryInterface.php index f84971fdf..2ff20d720 100755 --- a/src/Repository/BlockRepositoryInterface.php +++ b/src/Repository/BlockRepositoryInterface.php @@ -16,21 +16,12 @@ interface BlockRepositoryInterface extends RepositoryInterface { - public function createListQueryBuilder(string $localeCode): QueryBuilder; - public function findEnabledByCode(string $code, string $channelCode): ?BlockInterface; public function findByCollectionCode( string $collectionCode, - string $localeCode, - string $channelCode, - ): array; - - public function findByProductCode( - string $productCode, - string $localeCode, string $channelCode, ): array; - public function findByNamePart(string $phrase, ?string $locale = null): array; + public function findByNamePart(string $phrase): array; } diff --git a/src/Resources/config/config.yml b/src/Resources/config/config.yml index cd3f466d4..460bb44b0 100755 --- a/src/Resources/config/config.yml +++ b/src/Resources/config/config.yml @@ -9,7 +9,6 @@ parameters: bitbag_validation_group: [bitbag] bitbag_sylius_cms_plugin.form.type.block.validation_groups: "%bitbag_validation_group%" bitbag_sylius_cms_plugin.form.type.block_content.validation_groups: "%bitbag_validation_group%" - bitbag_sylius_cms_plugin.form.type.translation.block.validation_groups: "%bitbag_validation_group%" bitbag_sylius_cms_plugin.form.type.block_image.validation_groups: "%bitbag_validation_group%" bitbag_sylius_cms_plugin.form.type.page.validation_groups: "%bitbag_validation_group%" bitbag_sylius_cms_plugin.form.type.translation.page.validation_groups: "%bitbag_validation_group%" diff --git a/src/Resources/config/doctrine/Block.orm.xml b/src/Resources/config/doctrine/Block.orm.xml index b62cc1115..59ddba9ec 100644 --- a/src/Resources/config/doctrine/Block.orm.xml +++ b/src/Resources/config/doctrine/Block.orm.xml @@ -27,44 +27,36 @@ - - + + - + - - - - - - - - - - + + + + + + + + - - + + - + - + - - - - - - diff --git a/src/Resources/config/doctrine/BlockTranslation.orm.xml b/src/Resources/config/doctrine/BlockTranslation.orm.xml deleted file mode 100644 index f6ebc175a..000000000 --- a/src/Resources/config/doctrine/BlockTranslation.orm.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - diff --git a/src/Resources/config/grids/admin/block.yml b/src/Resources/config/grids/admin/block.yml index 759bb4af8..a1a83f4c1 100755 --- a/src/Resources/config/grids/admin/block.yml +++ b/src/Resources/config/grids/admin/block.yml @@ -5,9 +5,6 @@ sylius_grid: name: doctrine/orm options: class: "%bitbag_sylius_cms_plugin.model.block.class%" - repository: - method: createListQueryBuilder - arguments: ["%locale%"] sorting: code: asc limits: [10, 25, 50] diff --git a/src/Resources/config/resources/block.yml b/src/Resources/config/resources/block.yml index 119d65ea8..131137059 100755 --- a/src/Resources/config/resources/block.yml +++ b/src/Resources/config/resources/block.yml @@ -8,8 +8,4 @@ sylius_resource: form: BitBag\SyliusCmsPlugin\Form\Type\BlockType repository: BitBag\SyliusCmsPlugin\Repository\BlockRepository controller: BitBag\SyliusCmsPlugin\Controller\BlockController - factory: Sylius\Component\Resource\Factory\TranslatableFactory - translation: - classes: - model: BitBag\SyliusCmsPlugin\Entity\BlockTranslation - interface: BitBag\SyliusCmsPlugin\Entity\BlockTranslationInterface + factory: Sylius\Component\Resource\Factory\Factory diff --git a/src/Resources/config/routing/admin/block.yml b/src/Resources/config/routing/admin/block.yml index d913040fc..5025d02b7 100755 --- a/src/Resources/config/routing/admin/block.yml +++ b/src/Resources/config/routing/admin/block.yml @@ -41,7 +41,6 @@ bitbag_sylius_cms_plugin_admin_ajax_block_by_name_phrase: method: findByNamePart arguments: phrase: $phrase - locale: null bitbag_sylius_cms_plugin_admin_ajax_block_by_code: path: /ajax/blocks/code diff --git a/src/Resources/config/routing/shop/block.yml b/src/Resources/config/routing/shop/block.yml index d027a36cc..79eb47675 100755 --- a/src/Resources/config/routing/shop/block.yml +++ b/src/Resources/config/routing/shop/block.yml @@ -20,19 +20,4 @@ bitbag_sylius_cms_plugin_shop_block_index_by_collection_code: method: findByCollectionCode arguments: - $collectionCode - - "expr:service('sylius.context.locale').getLocaleCode()" - - "expr:service('sylius.context.channel').getChannel().getCode()" - -bitbag_sylius_cms_plugin_shop_block_index_by_product_code: - path: /blocks/product/{productCode} - methods: [GET] - defaults: - _controller: bitbag_sylius_cms_plugin.controller.block::indexAction - _sylius: - template: $template - repository: - method: findByProductCode - arguments: - - $productCode - - "expr:service('sylius.context.locale').getLocaleCode()" - "expr:service('sylius.context.channel').getChannel().getCode()" diff --git a/src/Resources/config/serialization/BlockTranslation.xml b/src/Resources/config/serialization/BlockTranslation.xml deleted file mode 100644 index 10c34736c..000000000 --- a/src/Resources/config/serialization/BlockTranslation.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - shop:cms:read - - - diff --git a/src/Resources/config/serializer/Entity.Block.yml b/src/Resources/config/serializer/Entity.Block.yml index 0ddd253bf..785a05373 100644 --- a/src/Resources/config/serializer/Entity.Block.yml +++ b/src/Resources/config/serializer/Entity.Block.yml @@ -11,10 +11,6 @@ BitBag\SyliusCmsPlugin\Entity\Block: expose: true type: string groups: [Autocomplete] - contents: - expose: true - type: iterable - groups: [Default] virtual_properties: getName: serialized_name: name diff --git a/src/Resources/config/services/fixture.xml b/src/Resources/config/services/fixture.xml index 4ec3a4558..0a6be88cb 100644 --- a/src/Resources/config/services/fixture.xml +++ b/src/Resources/config/services/fixture.xml @@ -31,13 +31,7 @@ - - - - - - diff --git a/src/Resources/config/services/form.xml b/src/Resources/config/services/form.xml index 5c46b9591..9edf54372 100644 --- a/src/Resources/config/services/form.xml +++ b/src/Resources/config/services/form.xml @@ -2,7 +2,7 @@ - BitBag\SyliusCmsPlugin\Form\Type\BlockContent\BlockContentTextConfigurationType::TYPE + BitBag\SyliusCmsPlugin\Form\Type\BlockContent\BlockContentTextConfigurationType::TYPE @@ -17,13 +17,7 @@ BitBag\SyliusCmsPlugin\Entity\BlockContent %bitbag_sylius_cms_plugin.form.type.block_content.validation_groups% - - - - - - %bitbag_sylius_cms_plugin.model.block_translation.class% - %bitbag_sylius_cms_plugin.form.type.translation.block.validation_groups% + @@ -92,7 +86,7 @@ - + diff --git a/src/Resources/config/services/importer.xml b/src/Resources/config/services/importer.xml index c26824853..5903792b1 100644 --- a/src/Resources/config/services/importer.xml +++ b/src/Resources/config/services/importer.xml @@ -22,7 +22,6 @@ - diff --git a/src/Resources/config/validation/Block.xml b/src/Resources/config/validation/Block.xml index 26e369571..94148725d 100644 --- a/src/Resources/config/validation/Block.xml +++ b/src/Resources/config/validation/Block.xml @@ -38,9 +38,5 @@ - - - - diff --git a/src/Resources/config/validation/BlockTranslation.xml b/src/Resources/config/validation/BlockTranslation.xml deleted file mode 100644 index 61da5b5dd..000000000 --- a/src/Resources/config/validation/BlockTranslation.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - diff --git a/src/Resources/translations/messages.en.yml b/src/Resources/translations/messages.en.yml index 377eefe4b..cbb9c5059 100755 --- a/src/Resources/translations/messages.en.yml +++ b/src/Resources/translations/messages.en.yml @@ -62,3 +62,6 @@ bitbag_sylius_cms_plugin: publish_at: Publish at page_will_be_publish_at: This page will be publish at save_with_original_name: Save with original name + block_content: + type: + content_text: Text content diff --git a/src/Resources/views/Block/Crud/_form.html.twig b/src/Resources/views/Block/Crud/_form.html.twig index f6ed4db1e..28d213306 100755 --- a/src/Resources/views/Block/Crud/_form.html.twig +++ b/src/Resources/views/Block/Crud/_form.html.twig @@ -9,26 +9,21 @@ {{ form_row(form.name) }} {{ form_row(form.enabled) }} {{ form_row(form.channels) }} + {{ form_row(form.locales) }} {{ form_row(form.collections) }}
-
+

{{ 'sylius.ui.configuration'|trans }}

-
-
+
+
{{ form_row(form.contents) }}
- -
-
- {{ translationForm(form.translations, resource) }} -
-
From 12602a06fe9c6d0edf3fd0b6041831168e464dc8 Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 25 Jun 2024 13:06:02 +0200 Subject: [PATCH 03/27] OP-321: Tests adjustments --- features/api/viewing_blocks.feature | 1 - spec/Entity/BlockTranslationSpec.php | 47 ---- spec/Importer/BlockImporterSpec.php | 13 +- .../packages/bitbag_sylius_cms_plugin.yaml | 65 ----- tests/Behat/Context/Setup/BlockContext.php | 12 +- .../DataFixtures/ORM/Api/BlockTest/block.yml | 31 --- tests/Functional/Fixture/BlockFixtureTest.php | 248 ------------------ .../BlockTest/test_it_get_block_by_id.json | 18 +- .../Api/BlockTest/test_it_get_blocks.json | 44 +--- ...test_it_finds_block_by_collection_code.yml | 22 -- .../test_it_finds_block_by_product_code.yml | 29 -- .../Repository/BlockRepositoryTest.php | 17 +- 12 files changed, 9 insertions(+), 538 deletions(-) delete mode 100755 spec/Entity/BlockTranslationSpec.php diff --git a/features/api/viewing_blocks.feature b/features/api/viewing_blocks.feature index de2888844..c2453c011 100644 --- a/features/api/viewing_blocks.feature +++ b/features/api/viewing_blocks.feature @@ -19,5 +19,4 @@ Feature: Getting data from cms blocks Scenario: Displaying block Given I view block with code "block-1" Then I should see block name - And I should see block content diff --git a/spec/Entity/BlockTranslationSpec.php b/spec/Entity/BlockTranslationSpec.php deleted file mode 100755 index 2bc57c894..000000000 --- a/spec/Entity/BlockTranslationSpec.php +++ /dev/null @@ -1,47 +0,0 @@ -shouldHaveType(ResourceInterface::class); - } - - public function it_is_a_resource(): void - { - $this->shouldHaveType(ResourceInterface::class); - } - - public function it_implements_block_translation_interface(): void - { - $this->shouldHaveType(BlockTranslationInterface::class); - $this->shouldHaveType(TranslationInterface::class); - } - - public function it_allows_access_via_properties(): void - { - $this->setName('Escobar favorite quote'); - $this->getName()->shouldReturn('Escobar favorite quote'); - - $this->setLink('https://en.wikipedia.org/wiki/Pablo_Escobar'); - $this->getLink()->shouldReturn('https://en.wikipedia.org/wiki/Pablo_Escobar'); - - $this->setContent('Plata o plomo'); - $this->getContent()->shouldReturn('Plata o plomo'); - } -} diff --git a/spec/Importer/BlockImporterSpec.php b/spec/Importer/BlockImporterSpec.php index c7a5cd00b..a4181fade 100644 --- a/spec/Importer/BlockImporterSpec.php +++ b/spec/Importer/BlockImporterSpec.php @@ -17,7 +17,6 @@ use BitBag\SyliusCmsPlugin\Resolver\ImporterCollectionsResolverInterface; use BitBag\SyliusCmsPlugin\Resolver\ResourceResolverInterface; use PhpSpec\ObjectBehavior; -use Sylius\Component\Locale\Context\LocaleContextInterface; use Symfony\Component\Validator\ConstraintViolationList; use Symfony\Component\Validator\Validator\ValidatorInterface; @@ -25,7 +24,6 @@ final class BlockImporterSpec extends ObjectBehavior { public function let( ResourceResolverInterface $blockResourceResolver, - LocaleContextInterface $localeContext, ImporterCollectionsResolverInterface $importerCollectionsResolver, ImporterChannelsResolverInterface $importerChannelsResolver, ImporterProductsResolverInterface $importerProductsResolver, @@ -34,7 +32,6 @@ public function let( ) { $this->beConstructedWith( $blockResourceResolver, - $localeContext, $importerCollectionsResolver, $importerChannelsResolver, $importerProductsResolver, @@ -51,7 +48,6 @@ public function it_is_initializable() public function it_imports_block( ResourceResolverInterface $blockResourceResolver, - LocaleContextInterface $localeContext, ImporterCollectionsResolverInterface $importerCollectionsResolver, ImporterChannelsResolverInterface $importerChannelsResolver, ImporterProductsResolverInterface $importerProductsResolver, @@ -59,18 +55,11 @@ public function it_imports_block( BlockRepositoryInterface $blockRepository, BlockInterface $block ) { - $row = ['name_pl' => 'name', 'content_pl' => 'content', 'link_pl' => 'link', 'code' => 'block_code']; + $row = ['name_pl' => 'name', 'code' => 'block_code']; $blockResourceResolver->getResource('block_code')->willReturn($block); - $localeContext->getLocaleCode()->willReturn('en_US'); - $block->setCode('block_code')->shouldBeCalled(); - $block->setFallbackLocale('en_US')->shouldBeCalled(); - $block->setCurrentLocale('pl')->shouldBeCalled(); - $block->setName('name')->shouldBeCalled(); - $block->setLink('link')->shouldBeCalled(); - $block->setContent('content')->shouldBeCalled(); $importerCollectionsResolver->resolve($block, null)->shouldBeCalled(); $importerChannelsResolver->resolve($block, null)->shouldBeCalled(); diff --git a/tests/Application/config/packages/bitbag_sylius_cms_plugin.yaml b/tests/Application/config/packages/bitbag_sylius_cms_plugin.yaml index e3f397167..423efca8b 100644 --- a/tests/Application/config/packages/bitbag_sylius_cms_plugin.yaml +++ b/tests/Application/config/packages/bitbag_sylius_cms_plugin.yaml @@ -40,90 +40,25 @@ sylius_fixtures: homepage_products_info: channels: - "FASHION_WEB" - translations: - en_US: - content: | -
- Click one of the below products to see what you can do with the blocks in your product view! -
collection_info_block: channels: - "FASHION_WEB" collections: - "products" - translations: - en_US: - content: | -
- The block you can see on the left is just a block associated with a collection named Products -
-

With this feature, you can render any block you want on the product page, like size table, delivery information, or even promotion banner.

-

It's done with a simple controller render:

-
{{ render(path('bitbag_sylius_cms_plugin_shop_block_index_by_collection_code', {'collectionCode' : 'products', 'template' : '@BitBagSyliusCmsPlugin/Shop/Block/index.html.twig'})) }}
product_info_block: channels: - "FASHION_WEB" - products: 5 - translations: - en_US: - content: | -
On the other hand, the block on the right is a block associated with specific products.
-

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

-

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

-
{{ render(path('bitbag_sylius_cms_plugin_shop_block_index_by_product_code', {'productCode' : product.code, 'template' : '@BitBagSyliusCmsPlugin/Shop/Block/index.html.twig'})) }}
homepage_intro: channels: - "FASHION_WEB" - translations: - en_US: - content: | -

Blocks

-

- The left block is rendered with the usage of the particular controller like this: -

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

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

-

- The other three blocks, including this one you are reading right now, are using Twig helper method. -

- -
-                                            bitbag_cms_render_block('homepage_intro')
-                                            bitbag_cms_render_block('homepage_banner_image_1')
-                                            bitbag_cms_render_block('homepage_banner_image_2')
-                                            
lorem_ipsum: channels: - "FASHION_WEB" collections: - "homepage" - translations: - en_US: - content: | -

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus

-
    -
  • Morbi in sem quis dui placerat ornare. Pellentesque odio nisi, euismod in, pharetra a, ultricies in, diam. Sed arcu. Cras consequat.
  • -
  • Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus.
  • -
  • Phasellus ultrices nulla quis nibh. Quisque a lectus. Donec consectetuer ligula vulputate sem tristique cursus. Nam nulla quam, gravida non, commodo a, sodales sit amet, nisi.
  • -
  • Pellentesque fermentum dolor. Aliquam quam lectus, facilisis auctor, ultrices ut, elementum vulputate, nunc.
  • -
-

Pellentesque habitant morbi tristique sene

taxons_and_products_block: channels: - "FASHION_WEB" - productCodes: - - "666F_boyfriend_jeans_with_rips" - - "727F_patched_cropped_jeans" - - "111F_patched_jeans_with_fancy_badges" - taxons: - - "womens_jeans" - translations: - en_US: - name: "Womens jeans" media: options: custom: diff --git a/tests/Behat/Context/Setup/BlockContext.php b/tests/Behat/Context/Setup/BlockContext.php index 0d25adb70..f351f9bd8 100755 --- a/tests/Behat/Context/Setup/BlockContext.php +++ b/tests/Behat/Context/Setup/BlockContext.php @@ -52,23 +52,20 @@ public function thereIsABlockWithCode(string $code): void /** * @Given there is a block with :code code and :content content */ - public function thereIsABlockWithCodeAndContent(string $code, string $content): void + public function thereIsABlockWithCodeAndContent(string $code): void { - $block = $this->createBlock($code, $content); + $block = $this->createBlock($code); $this->saveBlock($block); } private function createBlock( ?string $code = null, - ?string $content = null, ChannelInterface $channel = null, ): BlockInterface { /** @var BlockInterface $block */ $block = $this->blockFactory->createNew(); - $block->setCurrentLocale('en_US'); - if (null === $channel && $this->sharedStorage->has('channel')) { $channel = $this->sharedStorage->get('channel'); } @@ -77,12 +74,7 @@ private function createBlock( $code = $this->randomStringGenerator->generate(); } - if (null === $content) { - $content = $this->randomStringGenerator->generate(); - } - $block->setCode($code); - $block->setContent($content); $block->addChannel($channel); return $block; diff --git a/tests/Functional/DataFixtures/ORM/Api/BlockTest/block.yml b/tests/Functional/DataFixtures/ORM/Api/BlockTest/block.yml index 67e66abd9..1ea8738e4 100644 --- a/tests/Functional/DataFixtures/ORM/Api/BlockTest/block.yml +++ b/tests/Functional/DataFixtures/ORM/Api/BlockTest/block.yml @@ -71,59 +71,28 @@ Sylius\Component\Core\Model\ProductVariant: product_variant1: product: '@product1' code: "code1" - -BitBag\SyliusCmsPlugin\Entity\BlockTranslation: - block1_translation: - name: 'translation_name_en_US' - locale: 'en_US' - content: 'translation_content_en_US' - link: 'translation_link_en_US' - block2_translation: - name: 'translation_name_en_US' - locale: 'en_US' - content: 'translation_content_en_US' - link: 'translation_link_en_US' - block3_translation: - name: 'translation_name_en_US' - locale: 'en_US' - content: 'translation_content_en_US' - link: 'translation_link_en_US' BitBag\SyliusCmsPlugin\Entity\Block: block1: code: 'block1-code' enabled: true - products: - - '@product1' collections: - '@collection1' channels: - '@channel' - translations: - - '@block1_translation' - taxons: - - '@taxon' block2: code: 'block2-code' enabled: true - products: - - '@product2' collections: - '@collection2' channels: - '@channel' - translations: - - '@block2_translation' block3: code: 'block3-code' enabled: false - products: - - '@product3' collections: - '@collection3' channels: - '@channel' - translations: - - '@block3_translation' BitBag\SyliusCmsPlugin\Entity\Collection: collection1: code: 'collection1-code' diff --git a/tests/Functional/Fixture/BlockFixtureTest.php b/tests/Functional/Fixture/BlockFixtureTest.php index 6916a941d..17e936ad9 100644 --- a/tests/Functional/Fixture/BlockFixtureTest.php +++ b/tests/Functional/Fixture/BlockFixtureTest.php @@ -105,118 +105,6 @@ public function custom_number_is_optional_but_must_be_integer(): void ], 'custom.*.number'); } - /** - * @test - */ - public function custom_last_four_products_is_optional_but_must_be_boolean(): void - { - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'last_four_products' => true, - ], - ], - ], - ], 'custom.*.last_four_products'); - - $this->assertPartialConfigurationIsInvalid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'last_four_products' => 'boolean', - ], - ], - ], - ], 'custom.*.last_four_products'); - } - - /** - * @test - */ - public function custom_products_is_optional_but_must_be_integer(): void - { - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'products' => 5, - ], - ], - ], - ], 'custom.*.products'); - - $this->assertPartialConfigurationIsInvalid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'enabled' => 'integer', - ], - ], - ], - ], 'custom.*.products'); - } - - /** - * @test - */ - public function custom_product_codes_is_optional_but_must_be_array(): void - { - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'productCodes' => [], - ], - ], - ], - ], 'custom.*.productCodes'); - - $this->assertPartialConfigurationIsInvalid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'enabled' => 'integer', - ], - ], - ], - ], 'custom.*.productCodes'); - } - - /** - * @test - */ - public function custom_translations_is_optional_but_must_be_array(): void - { - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'translations' => [], - ], - ], - ], - ], 'custom.*.translations'); - - $this->assertPartialConfigurationIsInvalid([ - [ - 'custom' => [ - 'custom_1' => [ - 'translations' => '', - ], - ], - ], - ], 'custom.*.translations'); - - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'custom_1' => [], - ], - ], - ], 'custom.*.translations'); - } - /** * @test */ @@ -263,142 +151,6 @@ public function custom_collections_is_optional_but_must_be_scalar_array(): void ], 'custom.*.collections'); } - /** - * @test - */ - public function custom_may_contain_name(): void - { - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'translations' => [ - 'en_US' => [ - 'name' => 'block', - ], - ], - ], - ], - ], - ], 'custom.*.translations.*.name'); - - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'translations' => [ - 'en_US' => [ - 'name' => '', - ], - ], - ], - ], - ], - ], 'custom.*.translations.*.name'); - } - - /** - * @test - */ - public function custom_may_contain_content(): void - { - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'translations' => [ - 'en_US' => [ - 'content' => 'block', - ], - ], - ], - ], - ], - ], 'custom.*.translations.*.content'); - - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'translations' => [ - 'en_US' => [ - 'content' => '', - ], - ], - ], - ], - ], - ], 'custom.*.translations.*.content'); - } - - /** - * @test - */ - public function custom_may_contain_link(): void - { - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'translations' => [ - 'en_US' => [ - 'link' => 'block', - ], - ], - ], - ], - ], - ], 'custom.*.translations.*.link'); - - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'translations' => [ - 'en_US' => [ - 'link' => '', - ], - ], - ], - ], - ], - ], 'custom.*.translations.*.link'); - } - - /** - * @test - */ - public function custom_may_contain_image_path(): void - { - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'translations' => [ - 'en_US' => [ - 'image_path' => '/path/to/img', - ], - ], - ], - ], - ], - ], 'custom.*.translations.*.image_path'); - - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'translations' => [ - 'en_US' => [ - 'image_path' => '', - ], - ], - ], - ], - ], - ], 'custom.*.translations.*.image_path'); - } - protected function getConfiguration(): BlockFixture { /** @var FixtureFactoryInterface $blockFixtureFactory */ diff --git a/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_block_by_id.json b/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_block_by_id.json index d4442784c..18560fbd8 100644 --- a/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_block_by_id.json +++ b/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_block_by_id.json @@ -13,24 +13,8 @@ "code": "collection1-code" } ], - "products": [ - "/api/v2/shop/products/MUG_SW" - ], "channels": [ "/api/v2/shop/channels/code" ], - "translations": { - "en_US": { - "@type": "BlockTranslation", - "name": "translation_name_en_US", - "content": "translation_content_en_US", - "link": "translation_link_en_US" - } - }, - "taxons": [ - { - "@id": "/api/v2/shop/taxons/menu_category", - "@type": "Taxon" - } - ] + "contents": [] } diff --git a/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_blocks.json b/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_blocks.json index 9a8d02cfb..7fa2cd847 100644 --- a/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_blocks.json +++ b/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_blocks.json @@ -17,26 +17,10 @@ "code": "collection1-code" } ], - "products": [ - "/api/v2/shop/products/MUG_SW" - ], "channels": [ "/api/v2/shop/channels/code" ], - "translations": { - "en_US": { - "@type": "BlockTranslation", - "name": "translation_name_en_US", - "content": "translation_content_en_US", - "link": "translation_link_en_US" - } - }, - "taxons": [ - { - "@id": "/api/v2/shop/taxons/menu_category", - "@type": "Taxon" - } - ] + "contents": [] }, { "@id": "/api/v2/shop/cms-plugin/blocks/@integer@", @@ -52,21 +36,10 @@ "code": "collection2-code" } ], - "products": [ - "/api/v2/shop/products/MUG_SW2" - ], "channels": [ "/api/v2/shop/channels/code" ], - "translations": { - "en_US": { - "@type": "BlockTranslation", - "name": "translation_name_en_US", - "content": "translation_content_en_US", - "link": "translation_link_en_US" - } - }, - "taxons": [] + "contents": [] }, { "@id": "/api/v2/shop/cms-plugin/blocks/@integer@", @@ -82,21 +55,10 @@ "code": "collection3-code" } ], - "products": [ - "/api/v2/shop/products/MUG_SW3" - ], "channels": [ "/api/v2/shop/channels/code" ], - "translations": { - "en_US": { - "@type": "BlockTranslation", - "name": "translation_name_en_US", - "content": "translation_content_en_US", - "link": "translation_link_en_US" - } - }, - "taxons": [] + "contents": [] } ], "hydra:totalItems": 3 diff --git a/tests/Integration/DataFixtures/ORM/BlockRepositoryTest/test_it_finds_block_by_collection_code.yml b/tests/Integration/DataFixtures/ORM/BlockRepositoryTest/test_it_finds_block_by_collection_code.yml index 61f111d7f..8e4fb1b0c 100644 --- a/tests/Integration/DataFixtures/ORM/BlockRepositoryTest/test_it_finds_block_by_collection_code.yml +++ b/tests/Integration/DataFixtures/ORM/BlockRepositoryTest/test_it_finds_block_by_collection_code.yml @@ -17,22 +17,6 @@ Sylius\Component\Core\Model\Channel: default_locale: '@locale' tax_calculation_strategy: 'order_items_based' base_currency: '@dollar' -BitBag\SyliusCmsPlugin\Entity\BlockTranslation: - block1_translation: - name: 'translation_name_en_US' - locale: 'en_US' - content: 'translation_content_en_US' - link: 'translation_link_en_US' - block2_translation: - name: 'translation_name_en_US' - locale: 'en_US' - content: 'translation_content_en_US' - link: 'translation_link_en_US' - block3_translation: - name: 'translation_name_en_US' - locale: 'en_US' - content: 'translation_content_en_US' - link: 'translation_link_en_US' BitBag\SyliusCmsPlugin\Entity\Block: block1: code: 'block1-code' @@ -41,8 +25,6 @@ BitBag\SyliusCmsPlugin\Entity\Block: - '@collection1' channels: - '@channel' - translations: - - '@block1_translation' block2: code: 'block2-code' enabled: true @@ -50,8 +32,6 @@ BitBag\SyliusCmsPlugin\Entity\Block: - '@collection2' channels: - '@channel' - translations: - - '@block2_translation' block3: code: 'block3-code' enabled: false @@ -59,8 +39,6 @@ BitBag\SyliusCmsPlugin\Entity\Block: - '@collection3' channels: - '@channel' - translations: - - '@block3_translation' BitBag\SyliusCmsPlugin\Entity\Collection: collection1: code: 'collection1-code' diff --git a/tests/Integration/DataFixtures/ORM/BlockRepositoryTest/test_it_finds_block_by_product_code.yml b/tests/Integration/DataFixtures/ORM/BlockRepositoryTest/test_it_finds_block_by_product_code.yml index b59eb71e9..1ea8738e4 100644 --- a/tests/Integration/DataFixtures/ORM/BlockRepositoryTest/test_it_finds_block_by_product_code.yml +++ b/tests/Integration/DataFixtures/ORM/BlockRepositoryTest/test_it_finds_block_by_product_code.yml @@ -71,57 +71,28 @@ Sylius\Component\Core\Model\ProductVariant: product_variant1: product: '@product1' code: "code1" - -BitBag\SyliusCmsPlugin\Entity\BlockTranslation: - block1_translation: - name: 'translation_name_en_US' - locale: 'en_US' - content: 'translation_content_en_US' - link: 'translation_link_en_US' - block2_translation: - name: 'translation_name_en_US' - locale: 'en_US' - content: 'translation_content_en_US' - link: 'translation_link_en_US' - block3_translation: - name: 'translation_name_en_US' - locale: 'en_US' - content: 'translation_content_en_US' - link: 'translation_link_en_US' BitBag\SyliusCmsPlugin\Entity\Block: block1: code: 'block1-code' enabled: true - products: - - '@product1' collections: - '@collection1' channels: - '@channel' - translations: - - '@block1_translation' block2: code: 'block2-code' enabled: true - products: - - '@product2' collections: - '@collection2' channels: - '@channel' - translations: - - '@block2_translation' block3: code: 'block3-code' enabled: false - products: - - '@product3' collections: - '@collection3' channels: - '@channel' - translations: - - '@block3_translation' BitBag\SyliusCmsPlugin\Entity\Collection: collection1: code: 'collection1-code' diff --git a/tests/Integration/Repository/BlockRepositoryTest.php b/tests/Integration/Repository/BlockRepositoryTest.php index f9bd8084a..a76f67933 100644 --- a/tests/Integration/Repository/BlockRepositoryTest.php +++ b/tests/Integration/Repository/BlockRepositoryTest.php @@ -41,21 +41,8 @@ public function test_it_finds_enabled_block_by_collection_code(): void $blockRepository = $this->getRepository(); - $block_array1 = $blockRepository->findByCollectionCode('collection1-code', 'en_US', 'code'); - $block_array3 = $blockRepository->findByCollectionCode('collection3-code', 'en_US', 'code'); - - self::assertNotEmpty($block_array1); - self::assertEmpty($block_array3); - } - - public function test_it_finds_enabled_block_by_product_code(): void - { - $this->loadFixturesFromFile('BlockRepositoryTest/test_it_finds_block_by_product_code.yml'); - - $blockRepository = $this->getRepository(); - - $block_array1 = $blockRepository->findByProductCode('MUG_SW', 'en_US', 'code'); - $block_array3 = $blockRepository->findByProductCode('MUG_SW3', 'en_US', 'code'); + $block_array1 = $blockRepository->findByCollectionCode('collection1-code', 'code'); + $block_array3 = $blockRepository->findByCollectionCode('collection3-code', 'code'); self::assertNotEmpty($block_array1); self::assertEmpty($block_array3); From 789ba2aea92327c24f7c27d77573bae5d52ab36d Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 25 Jun 2024 13:10:14 +0200 Subject: [PATCH 04/27] OP-321: PHPStan fix --- src/Importer/BlockImporter.php | 2 -- src/Resources/config/services/importer.xml | 1 - 2 files changed, 3 deletions(-) diff --git a/src/Importer/BlockImporter.php b/src/Importer/BlockImporter.php index d483de097..f2023280d 100644 --- a/src/Importer/BlockImporter.php +++ b/src/Importer/BlockImporter.php @@ -25,7 +25,6 @@ public function __construct( private ResourceResolverInterface $blockResourceResolver, private ImporterCollectionsResolverInterface $importerCollectionsResolver, private ImporterChannelsResolverInterface $importerChannelsResolver, - private ImporterProductsResolverInterface $importerProductsResolver, ValidatorInterface $validator, private BlockRepositoryInterface $blockRepository, ) { @@ -43,7 +42,6 @@ public function import(array $row): void $this->importerCollectionsResolver->resolve($block, $this->getColumnValue(self::COLLECTIONS_COLUMN, $row)); $this->importerChannelsResolver->resolve($block, $this->getColumnValue(self::CHANNELS_COLUMN, $row)); - $this->importerProductsResolver->resolve($block, $this->getColumnValue(self::PRODUCTS_COLUMN, $row)); $this->validateResource($block, ['bitbag']); $this->blockRepository->add($block); diff --git a/src/Resources/config/services/importer.xml b/src/Resources/config/services/importer.xml index 5903792b1..2857f77a6 100644 --- a/src/Resources/config/services/importer.xml +++ b/src/Resources/config/services/importer.xml @@ -24,7 +24,6 @@ - From e1b93db20be184af25c38817f0288e715b5370e6 Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 25 Jun 2024 13:12:16 +0200 Subject: [PATCH 05/27] OP-321: ECS auto fix --- src/Entity/BlockContent.php | 8 ++++---- src/Entity/LocaleAwareInterface.php | 1 - src/Entity/LocaleAwareTrait.php | 1 - src/Form/Type/BlockContentType.php | 4 ++-- src/Form/Type/BlockType.php | 2 +- src/Importer/BlockImporter.php | 1 - src/Repository/BlockRepositoryInterface.php | 1 - 7 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/Entity/BlockContent.php b/src/Entity/BlockContent.php index b0db2f7b8..7a4519240 100644 --- a/src/Entity/BlockContent.php +++ b/src/Entity/BlockContent.php @@ -12,13 +12,13 @@ final class BlockContent implements BlockContentInterface { - protected ?int $id; + private ?int $id; - protected ?string $type; + private ?string $type; - protected array $configuration = []; + private array $configuration = []; - protected ?BlockInterface $block = null; + private ?BlockInterface $block = null; public function getId(): ?int { diff --git a/src/Entity/LocaleAwareInterface.php b/src/Entity/LocaleAwareInterface.php index 80d4aeefe..0cd3117e2 100644 --- a/src/Entity/LocaleAwareInterface.php +++ b/src/Entity/LocaleAwareInterface.php @@ -6,7 +6,6 @@ * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career */ - declare(strict_types=1); namespace BitBag\SyliusCmsPlugin\Entity; diff --git a/src/Entity/LocaleAwareTrait.php b/src/Entity/LocaleAwareTrait.php index 9ba37728b..14215f584 100644 --- a/src/Entity/LocaleAwareTrait.php +++ b/src/Entity/LocaleAwareTrait.php @@ -6,7 +6,6 @@ * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career */ - declare(strict_types=1); namespace BitBag\SyliusCmsPlugin\Entity; diff --git a/src/Form/Type/BlockContentType.php b/src/Form/Type/BlockContentType.php index c4296b1c2..3b50456a2 100644 --- a/src/Form/Type/BlockContentType.php +++ b/src/Form/Type/BlockContentType.php @@ -65,7 +65,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $form = $event->getForm(); $formData = $form->getData(); - if ($formData !== null && $formData->getType() !== $data['type']) { + if (null !== $formData && $formData->getType() !== $data['type']) { $formData->setConfiguration([]); } @@ -77,7 +77,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void private function addConfigurationTypeToForm(FormEvent $event): void { $data = $event->getData(); - if ($data === null) { + if (null === $data) { return; } diff --git a/src/Form/Type/BlockType.php b/src/Form/Type/BlockType.php index b723c9a7d..588df0666 100755 --- a/src/Form/Type/BlockType.php +++ b/src/Form/Type/BlockType.php @@ -14,9 +14,9 @@ use Sylius\Bundle\ChannelBundle\Form\Type\ChannelChoiceType; use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; +use Symfony\Component\Form\Extension\Core\Type\CollectionType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\Form\Extension\Core\Type\CollectionType; final class BlockType extends AbstractResourceType { diff --git a/src/Importer/BlockImporter.php b/src/Importer/BlockImporter.php index f2023280d..5261460fb 100644 --- a/src/Importer/BlockImporter.php +++ b/src/Importer/BlockImporter.php @@ -14,7 +14,6 @@ use BitBag\SyliusCmsPlugin\Repository\BlockRepositoryInterface; use BitBag\SyliusCmsPlugin\Resolver\ImporterChannelsResolverInterface; use BitBag\SyliusCmsPlugin\Resolver\ImporterCollectionsResolverInterface; -use BitBag\SyliusCmsPlugin\Resolver\ImporterProductsResolverInterface; use BitBag\SyliusCmsPlugin\Resolver\ResourceResolverInterface; use Symfony\Component\Validator\Validator\ValidatorInterface; use Webmozart\Assert\Assert; diff --git a/src/Repository/BlockRepositoryInterface.php b/src/Repository/BlockRepositoryInterface.php index 2ff20d720..6ea8534d1 100755 --- a/src/Repository/BlockRepositoryInterface.php +++ b/src/Repository/BlockRepositoryInterface.php @@ -11,7 +11,6 @@ namespace BitBag\SyliusCmsPlugin\Repository; use BitBag\SyliusCmsPlugin\Entity\BlockInterface; -use Doctrine\ORM\QueryBuilder; use Sylius\Component\Resource\Repository\RepositoryInterface; interface BlockRepositoryInterface extends RepositoryInterface From 648df0c31528fd5abf1228f456a1e09dcf287e39 Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 25 Jun 2024 13:50:51 +0200 Subject: [PATCH 06/27] OP-321: Removed final word from BlockContent.php --- src/Entity/BlockContent.php | 10 +++++----- src/Entity/BlockContentInterface.php | 2 -- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Entity/BlockContent.php b/src/Entity/BlockContent.php index 7a4519240..dd0d3fe65 100644 --- a/src/Entity/BlockContent.php +++ b/src/Entity/BlockContent.php @@ -10,15 +10,15 @@ namespace BitBag\SyliusCmsPlugin\Entity; -final class BlockContent implements BlockContentInterface +class BlockContent implements BlockContentInterface { - private ?int $id; + protected ?int $id; - private ?string $type; + protected ?string $type; - private array $configuration = []; + protected array $configuration = []; - private ?BlockInterface $block = null; + protected ?BlockInterface $block = null; public function getId(): ?int { diff --git a/src/Entity/BlockContentInterface.php b/src/Entity/BlockContentInterface.php index 952e9552b..a993a3b75 100644 --- a/src/Entity/BlockContentInterface.php +++ b/src/Entity/BlockContentInterface.php @@ -14,8 +14,6 @@ interface BlockContentInterface extends ResourceInterface { - public function getId(): ?int; - public function getType(): ?string; public function setType(?string $type): void; From 55b8c540165a2f77acac71f45107e9674d3ee367 Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 25 Jun 2024 13:54:24 +0200 Subject: [PATCH 07/27] OP-321: Remove wrong migration --- src/Migrations/Version20240621093611.php | 37 ------------------------ 1 file changed, 37 deletions(-) delete mode 100644 src/Migrations/Version20240621093611.php diff --git a/src/Migrations/Version20240621093611.php b/src/Migrations/Version20240621093611.php deleted file mode 100644 index 8eab82fed..000000000 --- a/src/Migrations/Version20240621093611.php +++ /dev/null @@ -1,37 +0,0 @@ -addSql('CREATE TABLE bitbag_cms_block_content (id INT AUTO_INCREMENT NOT NULL, block_id INT DEFAULT NULL, type VARCHAR(255) NOT NULL, configuration JSON NOT NULL COMMENT \'(DC2Type:json)\', INDEX IDX_FAA763A8E9ED820C (block_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('ALTER TABLE bitbag_cms_block_content ADD CONSTRAINT FK_FAA763A8E9ED820C FOREIGN KEY (block_id) REFERENCES bitbag_cms_block (id)'); - $this->addSql('ALTER TABLE bitbag_cms_block ADD name VARCHAR(250) DEFAULT NULL'); - $this->addSql('ALTER TABLE bitbag_cms_block_translation DROP name, DROP link'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE bitbag_cms_block_content DROP FOREIGN KEY FK_FAA763A8E9ED820C'); - $this->addSql('DROP TABLE bitbag_cms_block_content'); - $this->addSql('ALTER TABLE bitbag_cms_block_translation ADD name VARCHAR(255) DEFAULT NULL, ADD link LONGTEXT DEFAULT NULL'); - $this->addSql('ALTER TABLE bitbag_cms_block DROP name'); - } -} From ae6f00a177eda687bc030b93314eb60a18a31f3e Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 25 Jun 2024 14:08:59 +0200 Subject: [PATCH 08/27] OP-321: Spec fix --- spec/Entity/BlockSpec.php | 24 ------------------------ spec/Importer/BlockImporterSpec.php | 4 ---- 2 files changed, 28 deletions(-) diff --git a/spec/Entity/BlockSpec.php b/spec/Entity/BlockSpec.php index 988f87756..190db4c18 100755 --- a/spec/Entity/BlockSpec.php +++ b/spec/Entity/BlockSpec.php @@ -45,18 +45,6 @@ public function it_toggles(): void $this->isEnabled()->shouldReturn(false); } - public function it_associates_products(ProductInterface $firstProduct, ProductInterface $secondProduct): void - { - $this->addProduct($firstProduct); - $this->hasProduct($firstProduct)->shouldReturn(true); - - $this->hasProduct($secondProduct)->shouldReturn(false); - - $this->removeProduct($firstProduct); - - $this->hasProduct($firstProduct)->shouldReturn(false); - } - public function it_associates_collections(CollectionInterface $firstCollection, CollectionInterface $secondCollection): void { $this->addCollection($firstCollection); @@ -80,16 +68,4 @@ public function it_associates_channels(ChannelInterface $firstChannel, ChannelIn $this->hasChannel($firstChannel)->shouldReturn(false); } - - public function it_associates_taxons(TaxonInterface $firstTaxon, TaxonInterface $secondTaxon): void - { - $this->addTaxon($firstTaxon); - $this->hasTaxon($firstTaxon)->shouldReturn(true); - - $this->hasTaxon($secondTaxon)->shouldReturn(false); - - $this->removeTaxon($firstTaxon); - - $this->hasTaxon($secondTaxon)->shouldReturn(false); - } } diff --git a/spec/Importer/BlockImporterSpec.php b/spec/Importer/BlockImporterSpec.php index a4181fade..cf4a53529 100644 --- a/spec/Importer/BlockImporterSpec.php +++ b/spec/Importer/BlockImporterSpec.php @@ -26,7 +26,6 @@ public function let( ResourceResolverInterface $blockResourceResolver, ImporterCollectionsResolverInterface $importerCollectionsResolver, ImporterChannelsResolverInterface $importerChannelsResolver, - ImporterProductsResolverInterface $importerProductsResolver, ValidatorInterface $validator, BlockRepositoryInterface $blockRepository ) { @@ -34,7 +33,6 @@ public function let( $blockResourceResolver, $importerCollectionsResolver, $importerChannelsResolver, - $importerProductsResolver, $validator, $blockRepository ); @@ -50,7 +48,6 @@ public function it_imports_block( ResourceResolverInterface $blockResourceResolver, ImporterCollectionsResolverInterface $importerCollectionsResolver, ImporterChannelsResolverInterface $importerChannelsResolver, - ImporterProductsResolverInterface $importerProductsResolver, ValidatorInterface $validator, BlockRepositoryInterface $blockRepository, BlockInterface $block @@ -63,7 +60,6 @@ public function it_imports_block( $importerCollectionsResolver->resolve($block, null)->shouldBeCalled(); $importerChannelsResolver->resolve($block, null)->shouldBeCalled(); - $importerProductsResolver->resolve($block, null)->shouldBeCalled(); $validator->validate($block, null, ['bitbag'])->willReturn(new ConstraintViolationList()); From 5132848dcca9ac6751b6f2d5d8252f2b9373cf58 Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 25 Jun 2024 14:47:51 +0200 Subject: [PATCH 09/27] OP-321: Behat fix and homepage render fix --- features/admin/adding_block.feature | 4 +--- features/admin/managing_blocks.feature | 2 +- src/Entity/Block.php | 7 +++++++ src/Entity/BlockInterface.php | 3 ++- tests/Behat/Context/Setup/BlockContext.php | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/features/admin/adding_block.feature b/features/admin/adding_block.feature index b133db9c3..93aa26346 100644 --- a/features/admin/adding_block.feature +++ b/features/admin/adding_block.feature @@ -12,7 +12,6 @@ Feature: Adding blocks Scenario: Adding block When I go to the create block page And I fill the code with "store_description" - And I fill the content with "

We have the best candies on the internet!

" And I add it Then I should be notified that the block has been created @@ -22,7 +21,6 @@ Feature: Adding blocks When I go to the create block page And I fill the code with "intro" And I add "Blog" and "Homepage" collections to it - And I fill the content with "Hello world!" And I add it Then I should be notified that the block has been created @@ -43,7 +41,7 @@ Feature: Adding blocks @ui Scenario: Trying to add block with too long data When I go to the create block page - And I fill "Code, Name, Content" fields with 251 characters + And I fill "Code, Name" fields with 251 characters And I try to add it Then I should be notified that "Code, Name" fields are too long diff --git a/features/admin/managing_blocks.feature b/features/admin/managing_blocks.feature index 22c4b0a44..c08e7eac4 100644 --- a/features/admin/managing_blocks.feature +++ b/features/admin/managing_blocks.feature @@ -18,7 +18,7 @@ Feature: Managing cms blocks @ui @javascript Scenario: Updating block - Given there is a block with "store_phone_number" code and "123456789" content + Given there is a block with "store_phone_number" code When I go to the update "store_phone_number" block page And I fill the content with "987654321" And I update it diff --git a/src/Entity/Block.php b/src/Entity/Block.php index d03f63024..0ed71c181 100755 --- a/src/Entity/Block.php +++ b/src/Entity/Block.php @@ -58,4 +58,11 @@ public function setName(?string $name): void { $this->name = $name; } + + public function getContent(): ?string + { + // TODO: empty for now for testing purposes, to be implemented in the future tasks + // related to the epic: https://bitbag.atlassian.net/browse/OP-312 + return ''; + } } diff --git a/src/Entity/BlockInterface.php b/src/Entity/BlockInterface.php index 562cc76bb..7401581f0 100755 --- a/src/Entity/BlockInterface.php +++ b/src/Entity/BlockInterface.php @@ -20,7 +20,8 @@ interface BlockInterface extends CollectionableInterface, ChannelsAwareInterface, BlockContentAwareInterface, - LocaleAwareInterface + LocaleAwareInterface, + ContentableInterface { public function getCode(): ?string; diff --git a/tests/Behat/Context/Setup/BlockContext.php b/tests/Behat/Context/Setup/BlockContext.php index f351f9bd8..29885340c 100755 --- a/tests/Behat/Context/Setup/BlockContext.php +++ b/tests/Behat/Context/Setup/BlockContext.php @@ -50,7 +50,7 @@ public function thereIsABlockWithCode(string $code): void } /** - * @Given there is a block with :code code and :content content + * @Given there is a block with :code code */ public function thereIsABlockWithCodeAndContent(string $code): void { From f5368fe60acae934c28980a0c153cf8eac4c304b Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 25 Jun 2024 14:59:42 +0200 Subject: [PATCH 10/27] OP-321: Behat fix and block name vlaidator --- features/admin/managing_blocks.feature | 1 - src/Resources/config/validation/Block.xml | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/features/admin/managing_blocks.feature b/features/admin/managing_blocks.feature index c08e7eac4..6b4241137 100644 --- a/features/admin/managing_blocks.feature +++ b/features/admin/managing_blocks.feature @@ -20,7 +20,6 @@ Feature: Managing cms blocks Scenario: Updating block Given there is a block with "store_phone_number" code When I go to the update "store_phone_number" block page - And I fill the content with "987654321" And I update it Then I should be notified that the block has been successfully updated diff --git a/src/Resources/config/validation/Block.xml b/src/Resources/config/validation/Block.xml index 94148725d..272b1ee50 100644 --- a/src/Resources/config/validation/Block.xml +++ b/src/Resources/config/validation/Block.xml @@ -38,5 +38,22 @@ + + + + + + + + + + + + + From 22f8bfb0f3ec2929bad412888a17cff3f4a65a6a Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 25 Jun 2024 15:05:24 +0200 Subject: [PATCH 11/27] OP-321: Translations --- src/Resources/translations/messages.cs.yml | 3 +++ src/Resources/translations/messages.cs_CZ.yml | 3 +++ src/Resources/translations/messages.de.yml | 3 +++ src/Resources/translations/messages.es.yml | 3 +++ src/Resources/translations/messages.fr.yml | 3 +++ src/Resources/translations/messages.hr.yml | 3 +++ src/Resources/translations/messages.lt.yml | 4 +++- src/Resources/translations/messages.nl.yml | 3 +++ src/Resources/translations/messages.pl.yml | 3 +++ src/Resources/translations/messages.ru.yml | 3 +++ src/Resources/translations/messages.sk.yml | 3 +++ src/Resources/translations/messages.uk.yml | 3 +++ 12 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/Resources/translations/messages.cs.yml b/src/Resources/translations/messages.cs.yml index ba4cbd5c1..a7472163e 100755 --- a/src/Resources/translations/messages.cs.yml +++ b/src/Resources/translations/messages.cs.yml @@ -6,6 +6,9 @@ bitbag_sylius_cms_plugin: pages: Stránky page: Stránka title: Titul + block_content: + type: + content_text: Text cms: content_management: Obsahový management cms: Obsahový management diff --git a/src/Resources/translations/messages.cs_CZ.yml b/src/Resources/translations/messages.cs_CZ.yml index ba4cbd5c1..a7472163e 100755 --- a/src/Resources/translations/messages.cs_CZ.yml +++ b/src/Resources/translations/messages.cs_CZ.yml @@ -6,6 +6,9 @@ bitbag_sylius_cms_plugin: pages: Stránky page: Stránka title: Titul + block_content: + type: + content_text: Text cms: content_management: Obsahový management cms: Obsahový management diff --git a/src/Resources/translations/messages.de.yml b/src/Resources/translations/messages.de.yml index 3d16cb13c..d79c026de 100755 --- a/src/Resources/translations/messages.de.yml +++ b/src/Resources/translations/messages.de.yml @@ -56,3 +56,6 @@ bitbag_sylius_cms_plugin: import: Importieren successfully_imported: Die Daten wurden importiert. form_was_submitted_with_errors: "Das Formular wurde mit folgenden Fehlern übermittelt:" + block_content: + type: + content_text: Inhaltstext diff --git a/src/Resources/translations/messages.es.yml b/src/Resources/translations/messages.es.yml index cc481724e..9e832e76d 100755 --- a/src/Resources/translations/messages.es.yml +++ b/src/Resources/translations/messages.es.yml @@ -37,3 +37,6 @@ bitbag_sylius_cms_plugin: collections_subheader: Gestiona tus colecciones position: Posición title: Título + block_content: + type: + content_text: Texto diff --git a/src/Resources/translations/messages.fr.yml b/src/Resources/translations/messages.fr.yml index 904e9b1e9..a4de4a414 100755 --- a/src/Resources/translations/messages.fr.yml +++ b/src/Resources/translations/messages.fr.yml @@ -55,3 +55,6 @@ bitbag_sylius_cms_plugin: successfully_imported: Les données ont été importées. form_was_submitted_with_errors: "Le formulaire a les erreurs suivantes :" title: Titre + block_content: + type: + content_text: Texte diff --git a/src/Resources/translations/messages.hr.yml b/src/Resources/translations/messages.hr.yml index c19fddac3..9c26927f1 100755 --- a/src/Resources/translations/messages.hr.yml +++ b/src/Resources/translations/messages.hr.yml @@ -37,3 +37,6 @@ bitbag_sylius_cms_plugin: collections_subheader: Uredi kolekcije position: Pozicija (redosljed) title: Titula + block_content: + type: + content_text: Tekst diff --git a/src/Resources/translations/messages.lt.yml b/src/Resources/translations/messages.lt.yml index 055fa1245..629fccb48 100644 --- a/src/Resources/translations/messages.lt.yml +++ b/src/Resources/translations/messages.lt.yml @@ -54,4 +54,6 @@ bitbag_sylius_cms_plugin: csv_file: CSV failas successfully_imported: Duomenys sėkmingai importuoti. form_was_submitted_with_errors: "Forma pateikta su klaidomis:" - + block_content: + type: + content_text: Tekstas diff --git a/src/Resources/translations/messages.nl.yml b/src/Resources/translations/messages.nl.yml index 59c94b119..f7f8c2fad 100755 --- a/src/Resources/translations/messages.nl.yml +++ b/src/Resources/translations/messages.nl.yml @@ -36,3 +36,6 @@ bitbag_sylius_cms_plugin: collections_subheader: Beheer collecties position: Positie title: Titel + block_content: + type: + content_text: Tekst diff --git a/src/Resources/translations/messages.pl.yml b/src/Resources/translations/messages.pl.yml index f469d53bc..64a198f17 100755 --- a/src/Resources/translations/messages.pl.yml +++ b/src/Resources/translations/messages.pl.yml @@ -41,3 +41,6 @@ bitbag_sylius_cms_plugin: publish_at: Opublikuj page_will_be_publish_at: Strona zostanie opublikowana save_with_original_name: Zapisz z oryginalną nazwą + block_content: + type: + content_text: Tekst diff --git a/src/Resources/translations/messages.ru.yml b/src/Resources/translations/messages.ru.yml index f3b82f082..0564de330 100755 --- a/src/Resources/translations/messages.ru.yml +++ b/src/Resources/translations/messages.ru.yml @@ -54,3 +54,6 @@ bitbag_sylius_cms_plugin: csv_file: CSV файл successfully_imported: Данные успешно импортированы title: заглавие + block_content: + type: + content_text: Текст diff --git a/src/Resources/translations/messages.sk.yml b/src/Resources/translations/messages.sk.yml index 1185b5b14..d1ea95f5b 100644 --- a/src/Resources/translations/messages.sk.yml +++ b/src/Resources/translations/messages.sk.yml @@ -55,3 +55,6 @@ bitbag_sylius_cms_plugin: successfully_imported: Dáta boli naimportované form_was_submitted_with_errors: "Formulár obsahuje nasledovné chyby:" title: Titulok + block_content: + type: + content_text: Text diff --git a/src/Resources/translations/messages.uk.yml b/src/Resources/translations/messages.uk.yml index b2a528276..6ea8a63f5 100755 --- a/src/Resources/translations/messages.uk.yml +++ b/src/Resources/translations/messages.uk.yml @@ -54,3 +54,6 @@ bitbag_sylius_cms_plugin: csv_file: CSV файл successfully_imported: Дані успішно імпортовані title: заголовок + block_content: + type: + content_text: Текст From 833807adbad7ecf96e7f4299a41e06af82c1195e Mon Sep 17 00:00:00 2001 From: jkindly Date: Fri, 21 Jun 2024 13:22:48 +0200 Subject: [PATCH 12/27] OP-321: Init update block functionality --- src/Entity/Block.php | 19 ++-- src/Entity/BlockContent.php | 57 +++++++++++ src/Entity/BlockContentAwareInterface.php | 26 +++++ src/Entity/BlockContentAwareTrait.php | 48 +++++++++ src/Entity/BlockContentInterface.php | 30 ++++++ src/Entity/BlockInterface.php | 3 +- src/Entity/BlockTranslation.php | 26 ----- src/Entity/BlockTranslationInterface.php | 8 -- .../BlockContentTextConfigurationType.php | 32 ++++++ src/Form/Type/BlockContentType.php | 98 +++++++++++++++++++ src/Form/Type/BlockType.php | 22 +++-- .../Type/Translation/BlockTranslationType.php | 8 -- src/Migrations/Version20240621093611.php | 37 +++++++ src/Repository/BlockContentRepository.php | 17 ++++ src/Resources/config/config.yml | 1 + src/Resources/config/doctrine/Block.orm.xml | 8 ++ .../config/doctrine/BlockContent.orm.xml | 26 +++++ .../config/doctrine/BlockTranslation.orm.xml | 6 +- src/Resources/config/resources.yml | 1 + .../config/resources/block_content.yml | 10 ++ src/Resources/config/serialization/Block.xml | 3 + .../config/serialization/BlockTranslation.xml | 6 -- .../config/serializer/Entity.Block.yml | 4 + src/Resources/config/services/form.xml | 17 ++++ .../config/validation/BlockTranslation.xml | 24 ----- .../views/Block/Crud/_form.html.twig | 30 +++--- 26 files changed, 453 insertions(+), 114 deletions(-) create mode 100644 src/Entity/BlockContent.php create mode 100644 src/Entity/BlockContentAwareInterface.php create mode 100644 src/Entity/BlockContentAwareTrait.php create mode 100644 src/Entity/BlockContentInterface.php create mode 100644 src/Form/Type/BlockContent/BlockContentTextConfigurationType.php create mode 100644 src/Form/Type/BlockContentType.php create mode 100644 src/Migrations/Version20240621093611.php create mode 100755 src/Repository/BlockContentRepository.php create mode 100644 src/Resources/config/doctrine/BlockContent.orm.xml create mode 100644 src/Resources/config/resources/block_content.yml diff --git a/src/Entity/Block.php b/src/Entity/Block.php index 2037d6cec..807162112 100755 --- a/src/Entity/Block.php +++ b/src/Entity/Block.php @@ -21,6 +21,7 @@ class Block implements BlockInterface use ProductsAwareTrait; use TaxonAwareTrait; use ChannelsAwareTrait; + use BlockContentAwareTrait; use TranslatableTrait { __construct as protected initializeTranslationsCollection; } @@ -32,13 +33,14 @@ public function __construct() $this->initializeProductsCollection(); $this->initializeTaxonCollection(); $this->initializeChannelsCollection(); + $this->initializeContentsCollection(); } - /** @var int|null */ - protected $id; + protected ?int $id; - /** @var string|null */ - protected $code; + protected ?string $code; + + protected ?string $name; public function getId(): ?int { @@ -57,17 +59,12 @@ public function setCode(?string $code): void public function getName(): ?string { - /** @var BlockTranslationInterface $blockTranslationInterface */ - $blockTranslationInterface = $this->getBlockTranslation(); - - return $blockTranslationInterface->getName(); + return $this->name; } public function setName(?string $name): void { - /** @var BlockTranslationInterface $blockTranslationInterface */ - $blockTranslationInterface = $this->getBlockTranslation(); - $blockTranslationInterface->setName($name); + $this->name = $name; } public function getContent(): ?string diff --git a/src/Entity/BlockContent.php b/src/Entity/BlockContent.php new file mode 100644 index 000000000..ec598425b --- /dev/null +++ b/src/Entity/BlockContent.php @@ -0,0 +1,57 @@ +id; + } + + public function getType(): ?string + { + return $this->type; + } + + public function setType(?string $type): void + { + $this->type = $type; + } + + public function getConfiguration(): array + { + return $this->configuration; + } + + public function setConfiguration(array $configuration): void + { + $this->configuration = $configuration; + } + + public function getBlock(): ?BlockInterface + { + return $this->block; + } + + public function setBlock(?BlockInterface $block): void + { + $this->block = $block; + } +} diff --git a/src/Entity/BlockContentAwareInterface.php b/src/Entity/BlockContentAwareInterface.php new file mode 100644 index 000000000..52cae0d5a --- /dev/null +++ b/src/Entity/BlockContentAwareInterface.php @@ -0,0 +1,26 @@ +contents = new ArrayCollection(); + } + + public function getContents(): Collection + { + return $this->contents; + } + + public function hasContent(BlockContentInterface $contentItem): bool + { + return $this->contents->contains($contentItem); + } + + public function addContent(BlockContentInterface $contentItem): void + { + if (!$this->hasContent($contentItem)) { + $this->contents->add($contentItem); + } + } + + public function removeContent(BlockContentInterface $contentItem): void + { + if ($this->hasContent($contentItem)) { + $this->contents->removeElement($contentItem); + } + } +} diff --git a/src/Entity/BlockContentInterface.php b/src/Entity/BlockContentInterface.php new file mode 100644 index 000000000..952e9552b --- /dev/null +++ b/src/Entity/BlockContentInterface.php @@ -0,0 +1,30 @@ +name; - } - - public function setName(?string $name): void - { - $this->name = $name; - } - public function getContent(): ?string { return $this->content; @@ -50,14 +34,4 @@ public function getId(): ?int { return $this->id; } - - public function getLink(): ?string - { - return $this->link; - } - - public function setLink(?string $link): void - { - $this->link = $link; - } } diff --git a/src/Entity/BlockTranslationInterface.php b/src/Entity/BlockTranslationInterface.php index 28676df90..d09dec2a8 100755 --- a/src/Entity/BlockTranslationInterface.php +++ b/src/Entity/BlockTranslationInterface.php @@ -15,15 +15,7 @@ interface BlockTranslationInterface extends ResourceInterface, TranslationInterface { - public function getName(): ?string; - - public function setName(?string $name): void; - public function getContent(): ?string; public function setContent(?string $content): void; - - public function getLink(): ?string; - - public function setLink(?string $link): void; } diff --git a/src/Form/Type/BlockContent/BlockContentTextConfigurationType.php b/src/Form/Type/BlockContent/BlockContentTextConfigurationType.php new file mode 100644 index 000000000..e721b5706 --- /dev/null +++ b/src/Form/Type/BlockContent/BlockContentTextConfigurationType.php @@ -0,0 +1,32 @@ +setDefaults([ + 'label' => 'bitbag_sylius_cms_plugin.ui.text', + ]); + } + + public function getParent(): string + { + return WysiwygType::class; + } +} diff --git a/src/Form/Type/BlockContentType.php b/src/Form/Type/BlockContentType.php new file mode 100644 index 000000000..140f8b479 --- /dev/null +++ b/src/Form/Type/BlockContentType.php @@ -0,0 +1,98 @@ + $formType) { + $this->actionConfigurationTypes[$type] = $formType::class; + $this->actionTypes['bitbag_sylius_cms_plugin.block_content.action.' . $type] = $type; + } + } + + public function buildForm(FormBuilderInterface $builder, array $options) + { + $defaultActionType = current($this->actionTypes); + $defaultActionConfigurationType = $this->actionConfigurationTypes[$defaultActionType]; + + $builder + ->add('type', ChoiceType::class, [ + 'label' => 'sylius.ui.type', + 'choices' => $this->actionTypes, + ]) + ->add('configuration', $defaultActionConfigurationType, [ + 'label' => false, + ]) + ; + + $builder + ->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event): void { + $this->addConfigurationTypeToForm($event); + }) + ->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event): void { + /** @var array|null $data */ + $data = $event->getData(); + if (null === $data) { + return; + } + + $form = $event->getForm(); + $formData = $form->getData(); + + if ($formData !== null && $formData->getType() !== $data['type']) { + $formData->setConfiguration([]); + } + + $this->addConfigurationTypeToForm($event); + }) + ; + } + + private function addConfigurationTypeToForm(FormEvent $event): void + { + $data = $event->getData(); + if ($data === null) { + return; + } + + $form = $event->getForm(); + + $dataType = $data instanceof CatalogPromotionActionInterface ? $data->getType() : $data['type']; + + $actionConfigurationType = $this->actionConfigurationTypes[$dataType]; + $form->add('configuration', $actionConfigurationType, [ + 'label' => false, + ]); + } + + public function getBlockPrefix(): string + { + return 'bitbag_sylius_cms_plugin_block_content'; + } +} diff --git a/src/Form/Type/BlockType.php b/src/Form/Type/BlockType.php index 5463527cd..5160d9997 100755 --- a/src/Form/Type/BlockType.php +++ b/src/Form/Type/BlockType.php @@ -13,14 +13,13 @@ use BitBag\SyliusCmsPlugin\Entity\BlockInterface; use BitBag\SyliusCmsPlugin\Form\Type\Translation\BlockTranslationType; use Sylius\Bundle\ChannelBundle\Form\Type\ChannelChoiceType; -use Sylius\Bundle\ProductBundle\Form\Type\ProductAutocompleteChoiceType; use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; use Sylius\Bundle\ResourceBundle\Form\Type\ResourceTranslationsType; -use Sylius\Bundle\TaxonomyBundle\Form\Type\TaxonAutocompleteChoiceType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Validator\Constraints\Valid; +use \Symfony\Component\Form\Extension\Core\Type\CollectionType as SymfonyCollectionType; final class BlockType extends AbstractResourceType { @@ -34,6 +33,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'label' => 'bitbag_sylius_cms_plugin.ui.code', 'disabled' => null !== $block->getCode(), ]) + ->add('name', TextType::class, [ + 'label' => 'bitbag_sylius_cms_plugin.ui.name', + ]) ->add('collections', CollectionAutocompleteChoiceType::class, [ 'label' => 'bitbag_sylius_cms_plugin.ui.collections', 'multiple' => true, @@ -41,20 +43,20 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('enabled', CheckboxType::class, [ 'label' => 'bitbag_sylius_cms_plugin.ui.enabled', ]) - ->add('products', ProductAutocompleteChoiceType::class, [ - 'label' => 'bitbag_sylius_cms_plugin.ui.products', - 'multiple' => true, - ]) - ->add('taxons', TaxonAutocompleteChoiceType::class, [ - 'label' => 'bitbag_sylius_cms_plugin.ui.taxons', - 'multiple' => true, - ]) ->add('channels', ChannelChoiceType::class, [ 'label' => 'bitbag_sylius_cms_plugin.ui.channels', 'required' => false, 'multiple' => true, 'expanded' => true, ]) + ->add('contents', SymfonyCollectionType::class, [ + 'label' => 'sylius.ui.actions', + 'entry_type' => BlockContentType::class, + 'allow_add' => true, + 'allow_delete' => true, + 'by_reference' => false, + 'required' => false, + ]) ->add('translations', ResourceTranslationsType::class, [ 'label' => 'bitbag_sylius_cms_plugin.ui.contents', 'entry_type' => BlockTranslationType::class, diff --git a/src/Form/Type/Translation/BlockTranslationType.php b/src/Form/Type/Translation/BlockTranslationType.php index 2c74b196c..7d54f09d5 100644 --- a/src/Form/Type/Translation/BlockTranslationType.php +++ b/src/Form/Type/Translation/BlockTranslationType.php @@ -20,14 +20,6 @@ final class BlockTranslationType extends AbstractResourceType public function buildForm(FormBuilderInterface $builder, array $options): void { $builder - ->add('name', TextType::class, [ - 'label' => 'bitbag_sylius_cms_plugin.ui.name', - 'required' => false, - ]) - ->add('link', TextType::class, [ - 'label' => 'bitbag_sylius_cms_plugin.ui.link', - 'required' => false, - ]) ->add('content', WysiwygType::class, [ 'required' => false, ]) diff --git a/src/Migrations/Version20240621093611.php b/src/Migrations/Version20240621093611.php new file mode 100644 index 000000000..8eab82fed --- /dev/null +++ b/src/Migrations/Version20240621093611.php @@ -0,0 +1,37 @@ +addSql('CREATE TABLE bitbag_cms_block_content (id INT AUTO_INCREMENT NOT NULL, block_id INT DEFAULT NULL, type VARCHAR(255) NOT NULL, configuration JSON NOT NULL COMMENT \'(DC2Type:json)\', INDEX IDX_FAA763A8E9ED820C (block_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('ALTER TABLE bitbag_cms_block_content ADD CONSTRAINT FK_FAA763A8E9ED820C FOREIGN KEY (block_id) REFERENCES bitbag_cms_block (id)'); + $this->addSql('ALTER TABLE bitbag_cms_block ADD name VARCHAR(250) DEFAULT NULL'); + $this->addSql('ALTER TABLE bitbag_cms_block_translation DROP name, DROP link'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE bitbag_cms_block_content DROP FOREIGN KEY FK_FAA763A8E9ED820C'); + $this->addSql('DROP TABLE bitbag_cms_block_content'); + $this->addSql('ALTER TABLE bitbag_cms_block_translation ADD name VARCHAR(255) DEFAULT NULL, ADD link LONGTEXT DEFAULT NULL'); + $this->addSql('ALTER TABLE bitbag_cms_block DROP name'); + } +} diff --git a/src/Repository/BlockContentRepository.php b/src/Repository/BlockContentRepository.php new file mode 100755 index 000000000..0e70df7c0 --- /dev/null +++ b/src/Repository/BlockContentRepository.php @@ -0,0 +1,17 @@ + + + @@ -58,5 +60,11 @@ + + + + + + diff --git a/src/Resources/config/doctrine/BlockContent.orm.xml b/src/Resources/config/doctrine/BlockContent.orm.xml new file mode 100644 index 000000000..b928a5afc --- /dev/null +++ b/src/Resources/config/doctrine/BlockContent.orm.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Resources/config/doctrine/BlockTranslation.orm.xml b/src/Resources/config/doctrine/BlockTranslation.orm.xml index b3ebfa897..f6ebc175a 100644 --- a/src/Resources/config/doctrine/BlockTranslation.orm.xml +++ b/src/Resources/config/doctrine/BlockTranslation.orm.xml @@ -10,10 +10,6 @@ - - - - - \ No newline at end of file + diff --git a/src/Resources/config/resources.yml b/src/Resources/config/resources.yml index df0a8c254..52b3c7564 100755 --- a/src/Resources/config/resources.yml +++ b/src/Resources/config/resources.yml @@ -1,5 +1,6 @@ imports: - { resource: resources/block.yml } + - { resource: resources/block_content.yml } - { resource: resources/page.yml } - { resource: resources/frequently_asked_question.yml } - { resource: resources/collection.yml } diff --git a/src/Resources/config/resources/block_content.yml b/src/Resources/config/resources/block_content.yml new file mode 100644 index 000000000..194fbe3f9 --- /dev/null +++ b/src/Resources/config/resources/block_content.yml @@ -0,0 +1,10 @@ +sylius_resource: + resources: + bitbag_sylius_cms_plugin.block_content: + driver: doctrine/orm + classes: + model: BitBag\SyliusCmsPlugin\Entity\BlockContent + interface: BitBag\SyliusCmsPlugin\Entity\BlockContentInterface + form: BitBag\SyliusCmsPlugin\Form\Type\BlockContentType + repository: BitBag\SyliusCmsPlugin\Repository\BlockContentRepository + factory: Sylius\Component\Resource\Factory\TranslatableFactory diff --git a/src/Resources/config/serialization/Block.xml b/src/Resources/config/serialization/Block.xml index 409b83860..7f41a675b 100644 --- a/src/Resources/config/serialization/Block.xml +++ b/src/Resources/config/serialization/Block.xml @@ -28,5 +28,8 @@ shop:cms:read + + shop:cms:read + diff --git a/src/Resources/config/serialization/BlockTranslation.xml b/src/Resources/config/serialization/BlockTranslation.xml index b56254f8c..10c34736c 100644 --- a/src/Resources/config/serialization/BlockTranslation.xml +++ b/src/Resources/config/serialization/BlockTranslation.xml @@ -4,14 +4,8 @@ xsi:schemaLocation="http://symfony.com/schema/dic/serializer-mapping https://symfony.com/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd" > - - shop:cms:read - shop:cms:read - - shop:cms:read - diff --git a/src/Resources/config/serializer/Entity.Block.yml b/src/Resources/config/serializer/Entity.Block.yml index 785a05373..0ddd253bf 100644 --- a/src/Resources/config/serializer/Entity.Block.yml +++ b/src/Resources/config/serializer/Entity.Block.yml @@ -11,6 +11,10 @@ BitBag\SyliusCmsPlugin\Entity\Block: expose: true type: string groups: [Autocomplete] + contents: + expose: true + type: iterable + groups: [Default] virtual_properties: getName: serialized_name: name diff --git a/src/Resources/config/services/form.xml b/src/Resources/config/services/form.xml index 87053c778..5c46b9591 100644 --- a/src/Resources/config/services/form.xml +++ b/src/Resources/config/services/form.xml @@ -1,6 +1,10 @@ + + BitBag\SyliusCmsPlugin\Form\Type\BlockContent\BlockContentTextConfigurationType::TYPE + + @@ -10,6 +14,13 @@ + + BitBag\SyliusCmsPlugin\Entity\BlockContent + %bitbag_sylius_cms_plugin.form.type.block_content.validation_groups% + + + + %bitbag_sylius_cms_plugin.model.block_translation.class% %bitbag_sylius_cms_plugin.form.type.translation.block.validation_groups% @@ -79,6 +90,12 @@ + + + + + + diff --git a/src/Resources/config/validation/BlockTranslation.xml b/src/Resources/config/validation/BlockTranslation.xml index bd3e547f1..61da5b5dd 100644 --- a/src/Resources/config/validation/BlockTranslation.xml +++ b/src/Resources/config/validation/BlockTranslation.xml @@ -4,30 +4,6 @@ http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd"> - - - - - - - - - - - - - - - - - - - - diff --git a/src/Resources/views/Block/Crud/_form.html.twig b/src/Resources/views/Block/Crud/_form.html.twig index 979e42571..f6ed4db1e 100755 --- a/src/Resources/views/Block/Crud/_form.html.twig +++ b/src/Resources/views/Block/Crud/_form.html.twig @@ -1,28 +1,28 @@ {% from '@BitBagSyliusCmsPlugin/Macro/translationForm.html.twig' import translationForm %} {% form_theme form '@BitBagSyliusCmsPlugin/Form/theme.html.twig' %} -{% include '@BitBagSyliusCmsPlugin/Modal/_resourcePreview.html.twig' %} - -
+
{{ form_errors(form) }} {{ form_row(form.code) }} + {{ form_row(form.name) }} {{ form_row(form.enabled) }} - {{ form_row(form.products) }} - {{ form_row(form.taxons) }} - {{ form_row(form.collections) }} {{ form_row(form.channels) }} + {{ form_row(form.collections) }} +
+
+
- - - {{ 'bitbag_sylius_cms_plugin.ui.preview'|trans }} - +
+
+
+

{{ 'sylius.ui.configuration'|trans }}

+
+
+ {{ form_row(form.contents) }} +
+
From 8731d1ceab4a856ecd48017b55d8ad86acb84352 Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 25 Jun 2024 13:04:48 +0200 Subject: [PATCH 13/27] OP-321: Update block functionality --- src/Controller/BlockController.php | 4 -- src/Entity/Block.php | 59 ++----------------- src/Entity/BlockContent.php | 2 +- src/Entity/BlockContentAwareTrait.php | 2 + src/Entity/BlockInterface.php | 18 +----- src/Entity/BlockTranslation.php | 37 ------------ src/Entity/LocaleAwareInterface.php | 28 +++++++++ src/Entity/LocaleAwareTrait.php | 50 ++++++++++++++++ src/Fixture/BlockFixture.php | 13 ---- src/Fixture/Factory/BlockFixtureFactory.php | 45 -------------- .../BlockContentTextConfigurationType.php | 16 ++--- src/Form/Type/BlockContentType.php | 8 +-- src/Form/Type/BlockType.php | 16 ++--- .../Type/Translation/BlockTranslationType.php | 33 ----------- src/Importer/BlockImporter.php | 20 ------- src/Migrations/Version20240624122017.php | 57 ++++++++++++++++++ src/Repository/BlockRepository.php | 33 +---------- src/Repository/BlockRepositoryInterface.php | 11 +--- src/Resources/config/config.yml | 1 - src/Resources/config/doctrine/Block.orm.xml | 38 +++++------- .../config/doctrine/BlockTranslation.orm.xml | 15 ----- src/Resources/config/grids/admin/block.yml | 3 - src/Resources/config/resources/block.yml | 6 +- src/Resources/config/routing/admin/block.yml | 1 - src/Resources/config/routing/shop/block.yml | 15 ----- .../config/serialization/BlockTranslation.xml | 11 ---- .../config/serializer/Entity.Block.yml | 4 -- src/Resources/config/services/fixture.xml | 6 -- src/Resources/config/services/form.xml | 12 +--- src/Resources/config/services/importer.xml | 1 - src/Resources/config/validation/Block.xml | 4 -- .../config/validation/BlockTranslation.xml | 17 ------ src/Resources/translations/messages.en.yml | 3 + .../views/Block/Crud/_form.html.twig | 13 ++-- 34 files changed, 192 insertions(+), 410 deletions(-) delete mode 100755 src/Entity/BlockTranslation.php create mode 100644 src/Entity/LocaleAwareInterface.php create mode 100644 src/Entity/LocaleAwareTrait.php delete mode 100644 src/Form/Type/Translation/BlockTranslationType.php create mode 100644 src/Migrations/Version20240624122017.php delete mode 100644 src/Resources/config/doctrine/BlockTranslation.orm.xml delete mode 100644 src/Resources/config/serialization/BlockTranslation.xml delete mode 100644 src/Resources/config/validation/BlockTranslation.xml diff --git a/src/Controller/BlockController.php b/src/Controller/BlockController.php index 32b77a1a8..c19a9e79a 100755 --- a/src/Controller/BlockController.php +++ b/src/Controller/BlockController.php @@ -69,10 +69,6 @@ public function previewAction(Request $request): Response /** @var BlockInterface $block */ $block = $form->getData(); - $defaultLocale = $this->getParameter('locale'); - - $block->setFallbackLocale($request->get('_locale', $defaultLocale)); - $block->setCurrentLocale($request->get('_locale', $defaultLocale)); if (!$configuration->isHtmlRequest()) { Assert::true(null !== $this->viewHandler); diff --git a/src/Entity/Block.php b/src/Entity/Block.php index 807162112..d03f63024 100755 --- a/src/Entity/Block.php +++ b/src/Entity/Block.php @@ -11,34 +11,26 @@ namespace BitBag\SyliusCmsPlugin\Entity; use Sylius\Component\Resource\Model\ToggleableTrait; -use Sylius\Component\Resource\Model\TranslatableTrait; -use Sylius\Component\Resource\Model\TranslationInterface; class Block implements BlockInterface { use ToggleableTrait; - use CollectibleTrait; - use ProductsAwareTrait; - use TaxonAwareTrait; + use CollectionableTrait; use ChannelsAwareTrait; use BlockContentAwareTrait; - use TranslatableTrait { - __construct as protected initializeTranslationsCollection; - } + use LocaleAwareTrait; public function __construct() { - $this->initializeTranslationsCollection(); $this->initializeCollectionsCollection(); - $this->initializeProductsCollection(); - $this->initializeTaxonCollection(); $this->initializeChannelsCollection(); $this->initializeContentsCollection(); + $this->initializeLocalesCollection(); } protected ?int $id; - protected ?string $code; + protected ?string $code = null; protected ?string $name; @@ -66,47 +58,4 @@ public function setName(?string $name): void { $this->name = $name; } - - public function getContent(): ?string - { - /** @var BlockTranslationInterface $blockTranslationInterface */ - $blockTranslationInterface = $this->getBlockTranslation(); - - return $blockTranslationInterface->getContent(); - } - - public function setContent(?string $content): void - { - /** @var BlockTranslationInterface $blockTranslationInterface */ - $blockTranslationInterface = $this->getBlockTranslation(); - $blockTranslationInterface->setContent($content); - } - - public function getLink(): ?string - { - /** @var BlockTranslationInterface $blockTranslationInterface */ - $blockTranslationInterface = $this->getBlockTranslation(); - - return $blockTranslationInterface->getLink(); - } - - public function setLink(?string $link): void - { - /** @var BlockTranslationInterface $blockTranslationInterface */ - $blockTranslationInterface = $this->getBlockTranslation(); - $blockTranslationInterface->setLink($link); - } - - /** - * @return BlockTranslationInterface|TranslationInterface - */ - protected function getBlockTranslation(): TranslationInterface - { - return $this->getTranslation(); - } - - protected function createTranslation(): BlockTranslationInterface - { - return new BlockTranslation(); - } } diff --git a/src/Entity/BlockContent.php b/src/Entity/BlockContent.php index ec598425b..b0db2f7b8 100644 --- a/src/Entity/BlockContent.php +++ b/src/Entity/BlockContent.php @@ -18,7 +18,7 @@ final class BlockContent implements BlockContentInterface protected array $configuration = []; - protected ?BlockInterface $block; + protected ?BlockInterface $block = null; public function getId(): ?int { diff --git a/src/Entity/BlockContentAwareTrait.php b/src/Entity/BlockContentAwareTrait.php index c7044f819..62eca144f 100644 --- a/src/Entity/BlockContentAwareTrait.php +++ b/src/Entity/BlockContentAwareTrait.php @@ -35,6 +35,7 @@ public function hasContent(BlockContentInterface $contentItem): bool public function addContent(BlockContentInterface $contentItem): void { if (!$this->hasContent($contentItem)) { + $contentItem->setBlock($this); $this->contents->add($contentItem); } } @@ -43,6 +44,7 @@ public function removeContent(BlockContentInterface $contentItem): void { if ($this->hasContent($contentItem)) { $this->contents->removeElement($contentItem); + $contentItem->setBlock(null); } } } diff --git a/src/Entity/BlockInterface.php b/src/Entity/BlockInterface.php index 88ac4a8f3..562cc76bb 100755 --- a/src/Entity/BlockInterface.php +++ b/src/Entity/BlockInterface.php @@ -13,18 +13,14 @@ use Sylius\Component\Channel\Model\ChannelsAwareInterface; use Sylius\Component\Resource\Model\ResourceInterface; use Sylius\Component\Resource\Model\ToggleableInterface; -use Sylius\Component\Resource\Model\TranslatableInterface; interface BlockInterface extends ResourceInterface, - TranslatableInterface, ToggleableInterface, - ProductsAwareInterface, - TaxonAwareInterface, - CollectibleInterface, + CollectionableInterface, ChannelsAwareInterface, - ContentableInterface, - BlockContentAwareInterface + BlockContentAwareInterface, + LocaleAwareInterface { public function getCode(): ?string; @@ -33,12 +29,4 @@ public function setCode(?string $code): void; public function getName(): ?string; public function setName(?string $name): void; - - public function getContent(): ?string; - - public function setContent(?string $content): void; - - public function getLink(): ?string; - - public function setLink(?string $link): void; } diff --git a/src/Entity/BlockTranslation.php b/src/Entity/BlockTranslation.php deleted file mode 100755 index 68d877df8..000000000 --- a/src/Entity/BlockTranslation.php +++ /dev/null @@ -1,37 +0,0 @@ -content; - } - - public function setContent(?string $content): void - { - $this->content = $content; - } - - public function getId(): ?int - { - return $this->id; - } -} diff --git a/src/Entity/LocaleAwareInterface.php b/src/Entity/LocaleAwareInterface.php new file mode 100644 index 000000000..80d4aeefe --- /dev/null +++ b/src/Entity/LocaleAwareInterface.php @@ -0,0 +1,28 @@ +locales = new ArrayCollection(); + } + + public function getLocales(): Collection + { + return $this->locales; + } + + public function hasLocale(LocaleInterface $locale): bool + { + return $this->locales->contains($locale); + } + + public function addLocale(LocaleInterface $locale): void + { + if (!$this->hasLocale($locale)) { + $this->locales->add($locale); + } + } + + public function removeLocale(LocaleInterface $locale): void + { + if ($this->hasLocale($locale)) { + $this->locales->removeElement($locale); + } + } +} diff --git a/src/Fixture/BlockFixture.php b/src/Fixture/BlockFixture.php index 2a87c0f8c..2613dcdf8 100755 --- a/src/Fixture/BlockFixture.php +++ b/src/Fixture/BlockFixture.php @@ -41,21 +41,8 @@ protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void ->integerNode('number')->defaultNull()->end() ->booleanNode('last_four_products')->defaultFalse()->end() ->booleanNode('enabled')->defaultTrue()->end() - ->integerNode('products')->defaultNull()->end() - ->arrayNode('productCodes')->scalarPrototype()->end()->end() - ->arrayNode('taxons')->scalarPrototype()->end()->end() ->arrayNode('collections')->scalarPrototype()->end()->end() ->arrayNode('channels')->scalarPrototype()->end()->end() - ->arrayNode('translations') - ->arrayPrototype() - ->children() - ->scalarNode('name')->defaultNull()->end() - ->scalarNode('content')->defaultNull()->end() - ->scalarNode('link')->defaultNull()->end() - ->scalarNode('image_path')->defaultNull()->end() - ->end() - ->end() - ->end() ->end() ->end() ->end() diff --git a/src/Fixture/Factory/BlockFixtureFactory.php b/src/Fixture/Factory/BlockFixtureFactory.php index e4d6a6478..157bf2627 100755 --- a/src/Fixture/Factory/BlockFixtureFactory.php +++ b/src/Fixture/Factory/BlockFixtureFactory.php @@ -12,28 +12,15 @@ use BitBag\SyliusCmsPlugin\Assigner\ChannelsAssignerInterface; use BitBag\SyliusCmsPlugin\Assigner\CollectionsAssignerInterface; -use BitBag\SyliusCmsPlugin\Assigner\ProductsAssignerInterface; -use BitBag\SyliusCmsPlugin\Assigner\TaxonsAssignerInterface; use BitBag\SyliusCmsPlugin\Entity\BlockInterface; -use BitBag\SyliusCmsPlugin\Entity\BlockTranslationInterface; use BitBag\SyliusCmsPlugin\Repository\BlockRepositoryInterface; -use Sylius\Component\Channel\Context\ChannelContextInterface; -use Sylius\Component\Core\Model\ChannelInterface; -use Sylius\Component\Core\Repository\ProductRepositoryInterface; -use Sylius\Component\Locale\Context\LocaleContextInterface; use Sylius\Component\Resource\Factory\FactoryInterface; final class BlockFixtureFactory implements FixtureFactoryInterface { public function __construct( private FactoryInterface $blockFactory, - private FactoryInterface $blockTranslationFactory, private BlockRepositoryInterface $blockRepository, - private ProductRepositoryInterface $productRepository, - private ChannelContextInterface $channelContext, - private LocaleContextInterface $localeContext, - private ProductsAssignerInterface $productsAssigner, - private TaxonsAssignerInterface $taxonsAssigner, private CollectionsAssignerInterface $collectionsAssigner, private ChannelsAssignerInterface $channelAssigner, ) { @@ -66,44 +53,12 @@ private function createBlock(string $code, array $blockData): void /** @var BlockInterface $block */ $block = $this->blockFactory->createNew(); - $products = $blockData['products']; - if (null !== $products) { - $this->resolveProducts($block, $products); - } - $this->collectionsAssigner->assign($block, $blockData['collections']); - $this->productsAssigner->assign($block, $blockData['productCodes']); - $this->taxonsAssigner->assign($block, $blockData['taxons']); $this->channelAssigner->assign($block, $blockData['channels']); $block->setCode($code); $block->setEnabled($blockData['enabled']); - foreach ($blockData['translations'] as $localeCode => $translation) { - /** @var BlockTranslationInterface $blockTranslation */ - $blockTranslation = $this->blockTranslationFactory->createNew(); - - $blockTranslation->setLocale($localeCode); - $blockTranslation->setName($translation['name']); - $blockTranslation->setContent($translation['content']); - $blockTranslation->setLink($translation['link']); - $block->addTranslation($blockTranslation); - } - $this->blockRepository->add($block); } - - private function resolveProducts(BlockInterface $block, int $limit): void - { - /** @var ChannelInterface $channel */ - $channel = $this->channelContext->getChannel(); - $products = $this->productRepository->findLatestByChannel( - $channel, - $this->localeContext->getLocaleCode(), - $limit, - ); - foreach ($products as $product) { - $block->addProduct($product); - } - } } diff --git a/src/Form/Type/BlockContent/BlockContentTextConfigurationType.php b/src/Form/Type/BlockContent/BlockContentTextConfigurationType.php index e721b5706..d888eadcf 100644 --- a/src/Form/Type/BlockContent/BlockContentTextConfigurationType.php +++ b/src/Form/Type/BlockContent/BlockContentTextConfigurationType.php @@ -12,21 +12,23 @@ use BitBag\SyliusCmsPlugin\Form\Type\WysiwygType; use Symfony\Component\Form\AbstractType; -use Symfony\Component\OptionsResolver\OptionsResolver; +use Symfony\Component\Form\FormBuilderInterface; final class BlockContentTextConfigurationType extends AbstractType { public const TYPE = 'content_text'; - public function configureOptions(OptionsResolver $resolver): void + public function buildForm(FormBuilderInterface $builder, array $options): void { - $resolver->setDefaults([ - 'label' => 'bitbag_sylius_cms_plugin.ui.text', - ]); + $builder + ->add(self::TYPE, WysiwygType::class, [ + 'label' => 'bitbag_sylius_cms_plugin.ui.block_content.type.content_text', + ]) + ; } - public function getParent(): string + public function getBlockPrefix(): string { - return WysiwygType::class; + return 'bitbag_sylius_cms_plugin_block_content_text_configuration'; } } diff --git a/src/Form/Type/BlockContentType.php b/src/Form/Type/BlockContentType.php index 140f8b479..c4296b1c2 100644 --- a/src/Form/Type/BlockContentType.php +++ b/src/Form/Type/BlockContentType.php @@ -10,8 +10,8 @@ namespace BitBag\SyliusCmsPlugin\Form\Type; +use BitBag\SyliusCmsPlugin\Entity\BlockContentInterface; use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; -use Sylius\Component\Promotion\Model\CatalogPromotionActionInterface; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormEvent; @@ -32,11 +32,11 @@ public function __construct( foreach ($actionConfigurationTypes as $type => $formType) { $this->actionConfigurationTypes[$type] = $formType::class; - $this->actionTypes['bitbag_sylius_cms_plugin.block_content.action.' . $type] = $type; + $this->actionTypes['bitbag_sylius_cms_plugin.ui.block_content.type.' . $type] = $type; } } - public function buildForm(FormBuilderInterface $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options): void { $defaultActionType = current($this->actionTypes); $defaultActionConfigurationType = $this->actionConfigurationTypes[$defaultActionType]; @@ -83,7 +83,7 @@ private function addConfigurationTypeToForm(FormEvent $event): void $form = $event->getForm(); - $dataType = $data instanceof CatalogPromotionActionInterface ? $data->getType() : $data['type']; + $dataType = $data instanceof BlockContentInterface ? $data->getType() : $data['type']; $actionConfigurationType = $this->actionConfigurationTypes[$dataType]; $form->add('configuration', $actionConfigurationType, [ diff --git a/src/Form/Type/BlockType.php b/src/Form/Type/BlockType.php index 5160d9997..b723c9a7d 100755 --- a/src/Form/Type/BlockType.php +++ b/src/Form/Type/BlockType.php @@ -11,15 +11,12 @@ namespace BitBag\SyliusCmsPlugin\Form\Type; use BitBag\SyliusCmsPlugin\Entity\BlockInterface; -use BitBag\SyliusCmsPlugin\Form\Type\Translation\BlockTranslationType; use Sylius\Bundle\ChannelBundle\Form\Type\ChannelChoiceType; use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; -use Sylius\Bundle\ResourceBundle\Form\Type\ResourceTranslationsType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\Validator\Constraints\Valid; -use \Symfony\Component\Form\Extension\Core\Type\CollectionType as SymfonyCollectionType; +use Symfony\Component\Form\Extension\Core\Type\CollectionType; final class BlockType extends AbstractResourceType { @@ -49,20 +46,15 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'multiple' => true, 'expanded' => true, ]) - ->add('contents', SymfonyCollectionType::class, [ - 'label' => 'sylius.ui.actions', + ->add('locales') + ->add('contents', CollectionType::class, [ + 'label' => false, 'entry_type' => BlockContentType::class, 'allow_add' => true, 'allow_delete' => true, 'by_reference' => false, 'required' => false, ]) - ->add('translations', ResourceTranslationsType::class, [ - 'label' => 'bitbag_sylius_cms_plugin.ui.contents', - 'entry_type' => BlockTranslationType::class, - 'validation_groups' => ['bitbag_content'], - 'constraints' => [new Valid()], - ]) ; } diff --git a/src/Form/Type/Translation/BlockTranslationType.php b/src/Form/Type/Translation/BlockTranslationType.php deleted file mode 100644 index 7d54f09d5..000000000 --- a/src/Form/Type/Translation/BlockTranslationType.php +++ /dev/null @@ -1,33 +0,0 @@ -add('content', WysiwygType::class, [ - 'required' => false, - ]) - ; - } - - public function getBlockPrefix(): string - { - return 'bitbag_sylius_cms_plugin_text_translation'; - } -} diff --git a/src/Importer/BlockImporter.php b/src/Importer/BlockImporter.php index 589785cb4..d483de097 100644 --- a/src/Importer/BlockImporter.php +++ b/src/Importer/BlockImporter.php @@ -16,7 +16,6 @@ use BitBag\SyliusCmsPlugin\Resolver\ImporterCollectionsResolverInterface; use BitBag\SyliusCmsPlugin\Resolver\ImporterProductsResolverInterface; use BitBag\SyliusCmsPlugin\Resolver\ResourceResolverInterface; -use Sylius\Component\Locale\Context\LocaleContextInterface; use Symfony\Component\Validator\Validator\ValidatorInterface; use Webmozart\Assert\Assert; @@ -24,7 +23,6 @@ final class BlockImporter extends AbstractImporter implements BlockImporterInter { public function __construct( private ResourceResolverInterface $blockResourceResolver, - private LocaleContextInterface $localeContext, private ImporterCollectionsResolverInterface $importerCollectionsResolver, private ImporterChannelsResolverInterface $importerChannelsResolver, private ImporterProductsResolverInterface $importerProductsResolver, @@ -41,16 +39,7 @@ public function import(array $row): void Assert::notNull($code); /** @var BlockInterface $block */ $block = $this->blockResourceResolver->getResource($code); - $block->setCode($code); - $block->setFallbackLocale($this->localeContext->getLocaleCode()); - - foreach ($this->getAvailableLocales($this->getTranslatableColumns(), array_keys($row)) as $locale) { - $block->setCurrentLocale($locale); - $block->setName($this->getTranslatableColumnValue(self::NAME_COLUMN, $locale, $row)); - $block->setLink($this->getTranslatableColumnValue(self::LINK_COLUMN, $locale, $row)); - $block->setContent($this->getTranslatableColumnValue(self::CONTENT_COLUMN, $locale, $row)); - } $this->importerCollectionsResolver->resolve($block, $this->getColumnValue(self::COLLECTIONS_COLUMN, $row)); $this->importerChannelsResolver->resolve($block, $this->getColumnValue(self::CHANNELS_COLUMN, $row)); @@ -64,13 +53,4 @@ public function getResourceCode(): string { return 'block'; } - - private function getTranslatableColumns(): array - { - return [ - self::NAME_COLUMN, - self::CONTENT_COLUMN, - self::LINK_COLUMN, - ]; - } } diff --git a/src/Migrations/Version20240624122017.php b/src/Migrations/Version20240624122017.php new file mode 100644 index 000000000..29386e171 --- /dev/null +++ b/src/Migrations/Version20240624122017.php @@ -0,0 +1,57 @@ +addSql('CREATE TABLE bitbag_cms_block_locales (block_id INT NOT NULL, locale_id INT NOT NULL, INDEX IDX_E1F907BAE9ED820C (block_id), INDEX IDX_E1F907BAE559DFD1 (locale_id), PRIMARY KEY(block_id, locale_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE bitbag_cms_block_content (id INT AUTO_INCREMENT NOT NULL, block_id INT DEFAULT NULL, type VARCHAR(255) NOT NULL, configuration JSON NOT NULL COMMENT \'(DC2Type:json)\', INDEX IDX_FAA763A8E9ED820C (block_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('ALTER TABLE bitbag_cms_block_locales ADD CONSTRAINT FK_E1F907BAE9ED820C FOREIGN KEY (block_id) REFERENCES bitbag_cms_block (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE bitbag_cms_block_locales ADD CONSTRAINT FK_E1F907BAE559DFD1 FOREIGN KEY (locale_id) REFERENCES sylius_locale (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE bitbag_cms_block_content ADD CONSTRAINT FK_FAA763A8E9ED820C FOREIGN KEY (block_id) REFERENCES bitbag_cms_block (id)'); + $this->addSql('ALTER TABLE bitbag_cms_block_products DROP FOREIGN KEY FK_C4B9089F4584665A'); + $this->addSql('ALTER TABLE bitbag_cms_block_products DROP FOREIGN KEY FK_C4B9089FE9ED820C'); + $this->addSql('ALTER TABLE bitbag_cms_block_taxonomies DROP FOREIGN KEY FK_10C3E429E9ED820C'); + $this->addSql('ALTER TABLE bitbag_cms_block_taxonomies DROP FOREIGN KEY FK_10C3E429DE13F470'); + $this->addSql('ALTER TABLE bitbag_cms_block_translation DROP FOREIGN KEY FK_32897FDF2C2AC5D3'); + $this->addSql('DROP TABLE bitbag_cms_block_products'); + $this->addSql('DROP TABLE bitbag_cms_block_taxonomies'); + $this->addSql('DROP TABLE bitbag_cms_block_translation'); + $this->addSql('ALTER TABLE bitbag_cms_block ADD name VARCHAR(250) DEFAULT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('CREATE TABLE bitbag_cms_block_products (block_id INT NOT NULL, product_id INT NOT NULL, INDEX IDX_C4B9089FE9ED820C (block_id), INDEX IDX_C4B9089F4584665A (product_id), PRIMARY KEY(block_id, product_id)) DEFAULT CHARACTER SET utf8mb3 COLLATE `utf8mb3_unicode_ci` ENGINE = InnoDB COMMENT = \'\' '); + $this->addSql('CREATE TABLE bitbag_cms_block_taxonomies (block_id INT NOT NULL, taxon_id INT NOT NULL, INDEX IDX_10C3E429E9ED820C (block_id), INDEX IDX_10C3E429DE13F470 (taxon_id), PRIMARY KEY(block_id, taxon_id)) DEFAULT CHARACTER SET utf8mb3 COLLATE `utf8mb3_unicode_ci` ENGINE = InnoDB COMMENT = \'\' '); + $this->addSql('CREATE TABLE bitbag_cms_block_translation (id INT AUTO_INCREMENT NOT NULL, translatable_id INT NOT NULL, content LONGTEXT CHARACTER SET utf8mb3 DEFAULT NULL COLLATE `utf8mb3_unicode_ci`, locale VARCHAR(255) CHARACTER SET utf8mb3 NOT NULL COLLATE `utf8mb3_unicode_ci`, name VARCHAR(255) CHARACTER SET utf8mb3 DEFAULT NULL COLLATE `utf8mb3_unicode_ci`, link LONGTEXT CHARACTER SET utf8mb3 DEFAULT NULL COLLATE `utf8mb3_unicode_ci`, INDEX IDX_32897FDF2C2AC5D3 (translatable_id), UNIQUE INDEX bitbag_cms_block_translation_uniq_trans (translatable_id, locale), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb3 COLLATE `utf8mb3_unicode_ci` ENGINE = InnoDB COMMENT = \'\' '); + $this->addSql('ALTER TABLE bitbag_cms_block_products ADD CONSTRAINT FK_C4B9089F4584665A FOREIGN KEY (product_id) REFERENCES sylius_product (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE bitbag_cms_block_products ADD CONSTRAINT FK_C4B9089FE9ED820C FOREIGN KEY (block_id) REFERENCES bitbag_cms_block (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE bitbag_cms_block_taxonomies ADD CONSTRAINT FK_10C3E429E9ED820C FOREIGN KEY (block_id) REFERENCES bitbag_cms_block (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE bitbag_cms_block_taxonomies ADD CONSTRAINT FK_10C3E429DE13F470 FOREIGN KEY (taxon_id) REFERENCES sylius_taxon (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE bitbag_cms_block_translation ADD CONSTRAINT FK_32897FDF2C2AC5D3 FOREIGN KEY (translatable_id) REFERENCES bitbag_cms_block (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE bitbag_cms_block_locales DROP FOREIGN KEY FK_E1F907BAE9ED820C'); + $this->addSql('ALTER TABLE bitbag_cms_block_locales DROP FOREIGN KEY FK_E1F907BAE559DFD1'); + $this->addSql('ALTER TABLE bitbag_cms_block_content DROP FOREIGN KEY FK_FAA763A8E9ED820C'); + $this->addSql('DROP TABLE bitbag_cms_block_locales'); + $this->addSql('DROP TABLE bitbag_cms_block_content'); + $this->addSql('ALTER TABLE bitbag_cms_block DROP name'); + } +} diff --git a/src/Repository/BlockRepository.php b/src/Repository/BlockRepository.php index 4d32cc427..f6b7e71a1 100755 --- a/src/Repository/BlockRepository.php +++ b/src/Repository/BlockRepository.php @@ -16,8 +16,6 @@ class BlockRepository extends EntityRepository implements BlockRepositoryInterface { - use TranslationBasedAwareTrait; - public function createListQueryBuilder(string $localeCode): QueryBuilder { return $this->createQueryBuilder('o') @@ -43,18 +41,14 @@ public function findEnabledByCode(string $code, string $channelCode): ?BlockInte public function findByCollectionCode( string $collectionCode, - string $localeCode, string $channelCode, ): array { return $this->createQueryBuilder('o') - ->leftJoin('o.translations', 'translation') ->innerJoin('o.collections', 'collection') ->innerJoin('o.channels', 'channels') - ->andWhere('translation.locale = :localeCode') ->andWhere('collection.code = :collectionCode') ->andWhere('o.enabled = true') ->andWhere('channels.code = :channelCode') - ->setParameter('localeCode', $localeCode) ->setParameter('collectionCode', $collectionCode) ->setParameter('channelCode', $channelCode) ->getQuery() @@ -62,31 +56,10 @@ public function findByCollectionCode( ; } - public function findByProductCode( - string $productCode, - string $localeCode, - string $channelCode, - ): array { - return $this->createQueryBuilder('o') - ->leftJoin('o.translations', 'translation') - ->innerJoin('o.products', 'product') - ->innerJoin('o.channels', 'channels') - ->andWhere('translation.locale = :localeCode') - ->andWhere('product.code = :productCode') - ->andWhere('o.enabled = true') - ->andWhere('channels.code = :channelCode') - ->setParameter('localeCode', $localeCode) - ->setParameter('productCode', $productCode) - ->setParameter('channelCode', $channelCode) - ->getQuery() - ->getResult() - ; - } - - public function findByNamePart(string $phrase, ?string $locale = null): array + public function findByNamePart(string $phrase): array { - return $this->createTranslationBasedQueryBuilder($locale) - ->andWhere('translation.name LIKE :name') + return $this->createQueryBuilder('o') + ->andWhere('o.name LIKE :name') ->setParameter('name', '%' . $phrase . '%') ->getQuery() ->getResult() diff --git a/src/Repository/BlockRepositoryInterface.php b/src/Repository/BlockRepositoryInterface.php index f84971fdf..2ff20d720 100755 --- a/src/Repository/BlockRepositoryInterface.php +++ b/src/Repository/BlockRepositoryInterface.php @@ -16,21 +16,12 @@ interface BlockRepositoryInterface extends RepositoryInterface { - public function createListQueryBuilder(string $localeCode): QueryBuilder; - public function findEnabledByCode(string $code, string $channelCode): ?BlockInterface; public function findByCollectionCode( string $collectionCode, - string $localeCode, - string $channelCode, - ): array; - - public function findByProductCode( - string $productCode, - string $localeCode, string $channelCode, ): array; - public function findByNamePart(string $phrase, ?string $locale = null): array; + public function findByNamePart(string $phrase): array; } diff --git a/src/Resources/config/config.yml b/src/Resources/config/config.yml index cd3f466d4..460bb44b0 100755 --- a/src/Resources/config/config.yml +++ b/src/Resources/config/config.yml @@ -9,7 +9,6 @@ parameters: bitbag_validation_group: [bitbag] bitbag_sylius_cms_plugin.form.type.block.validation_groups: "%bitbag_validation_group%" bitbag_sylius_cms_plugin.form.type.block_content.validation_groups: "%bitbag_validation_group%" - bitbag_sylius_cms_plugin.form.type.translation.block.validation_groups: "%bitbag_validation_group%" bitbag_sylius_cms_plugin.form.type.block_image.validation_groups: "%bitbag_validation_group%" bitbag_sylius_cms_plugin.form.type.page.validation_groups: "%bitbag_validation_group%" bitbag_sylius_cms_plugin.form.type.translation.page.validation_groups: "%bitbag_validation_group%" diff --git a/src/Resources/config/doctrine/Block.orm.xml b/src/Resources/config/doctrine/Block.orm.xml index b62cc1115..59ddba9ec 100644 --- a/src/Resources/config/doctrine/Block.orm.xml +++ b/src/Resources/config/doctrine/Block.orm.xml @@ -27,44 +27,36 @@ - - + + - + - - - - - - - - - - + + + + + + + + - - + + - + - + - - - - - - diff --git a/src/Resources/config/doctrine/BlockTranslation.orm.xml b/src/Resources/config/doctrine/BlockTranslation.orm.xml deleted file mode 100644 index f6ebc175a..000000000 --- a/src/Resources/config/doctrine/BlockTranslation.orm.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - diff --git a/src/Resources/config/grids/admin/block.yml b/src/Resources/config/grids/admin/block.yml index 759bb4af8..a1a83f4c1 100755 --- a/src/Resources/config/grids/admin/block.yml +++ b/src/Resources/config/grids/admin/block.yml @@ -5,9 +5,6 @@ sylius_grid: name: doctrine/orm options: class: "%bitbag_sylius_cms_plugin.model.block.class%" - repository: - method: createListQueryBuilder - arguments: ["%locale%"] sorting: code: asc limits: [10, 25, 50] diff --git a/src/Resources/config/resources/block.yml b/src/Resources/config/resources/block.yml index 119d65ea8..131137059 100755 --- a/src/Resources/config/resources/block.yml +++ b/src/Resources/config/resources/block.yml @@ -8,8 +8,4 @@ sylius_resource: form: BitBag\SyliusCmsPlugin\Form\Type\BlockType repository: BitBag\SyliusCmsPlugin\Repository\BlockRepository controller: BitBag\SyliusCmsPlugin\Controller\BlockController - factory: Sylius\Component\Resource\Factory\TranslatableFactory - translation: - classes: - model: BitBag\SyliusCmsPlugin\Entity\BlockTranslation - interface: BitBag\SyliusCmsPlugin\Entity\BlockTranslationInterface + factory: Sylius\Component\Resource\Factory\Factory diff --git a/src/Resources/config/routing/admin/block.yml b/src/Resources/config/routing/admin/block.yml index d913040fc..5025d02b7 100755 --- a/src/Resources/config/routing/admin/block.yml +++ b/src/Resources/config/routing/admin/block.yml @@ -41,7 +41,6 @@ bitbag_sylius_cms_plugin_admin_ajax_block_by_name_phrase: method: findByNamePart arguments: phrase: $phrase - locale: null bitbag_sylius_cms_plugin_admin_ajax_block_by_code: path: /ajax/blocks/code diff --git a/src/Resources/config/routing/shop/block.yml b/src/Resources/config/routing/shop/block.yml index d027a36cc..79eb47675 100755 --- a/src/Resources/config/routing/shop/block.yml +++ b/src/Resources/config/routing/shop/block.yml @@ -20,19 +20,4 @@ bitbag_sylius_cms_plugin_shop_block_index_by_collection_code: method: findByCollectionCode arguments: - $collectionCode - - "expr:service('sylius.context.locale').getLocaleCode()" - - "expr:service('sylius.context.channel').getChannel().getCode()" - -bitbag_sylius_cms_plugin_shop_block_index_by_product_code: - path: /blocks/product/{productCode} - methods: [GET] - defaults: - _controller: bitbag_sylius_cms_plugin.controller.block::indexAction - _sylius: - template: $template - repository: - method: findByProductCode - arguments: - - $productCode - - "expr:service('sylius.context.locale').getLocaleCode()" - "expr:service('sylius.context.channel').getChannel().getCode()" diff --git a/src/Resources/config/serialization/BlockTranslation.xml b/src/Resources/config/serialization/BlockTranslation.xml deleted file mode 100644 index 10c34736c..000000000 --- a/src/Resources/config/serialization/BlockTranslation.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - shop:cms:read - - - diff --git a/src/Resources/config/serializer/Entity.Block.yml b/src/Resources/config/serializer/Entity.Block.yml index 0ddd253bf..785a05373 100644 --- a/src/Resources/config/serializer/Entity.Block.yml +++ b/src/Resources/config/serializer/Entity.Block.yml @@ -11,10 +11,6 @@ BitBag\SyliusCmsPlugin\Entity\Block: expose: true type: string groups: [Autocomplete] - contents: - expose: true - type: iterable - groups: [Default] virtual_properties: getName: serialized_name: name diff --git a/src/Resources/config/services/fixture.xml b/src/Resources/config/services/fixture.xml index 4ec3a4558..0a6be88cb 100644 --- a/src/Resources/config/services/fixture.xml +++ b/src/Resources/config/services/fixture.xml @@ -31,13 +31,7 @@ - - - - - - diff --git a/src/Resources/config/services/form.xml b/src/Resources/config/services/form.xml index 5c46b9591..9edf54372 100644 --- a/src/Resources/config/services/form.xml +++ b/src/Resources/config/services/form.xml @@ -2,7 +2,7 @@ - BitBag\SyliusCmsPlugin\Form\Type\BlockContent\BlockContentTextConfigurationType::TYPE + BitBag\SyliusCmsPlugin\Form\Type\BlockContent\BlockContentTextConfigurationType::TYPE @@ -17,13 +17,7 @@ BitBag\SyliusCmsPlugin\Entity\BlockContent %bitbag_sylius_cms_plugin.form.type.block_content.validation_groups% - - - - - - %bitbag_sylius_cms_plugin.model.block_translation.class% - %bitbag_sylius_cms_plugin.form.type.translation.block.validation_groups% + @@ -92,7 +86,7 @@ - + diff --git a/src/Resources/config/services/importer.xml b/src/Resources/config/services/importer.xml index c26824853..5903792b1 100644 --- a/src/Resources/config/services/importer.xml +++ b/src/Resources/config/services/importer.xml @@ -22,7 +22,6 @@ - diff --git a/src/Resources/config/validation/Block.xml b/src/Resources/config/validation/Block.xml index 26e369571..94148725d 100644 --- a/src/Resources/config/validation/Block.xml +++ b/src/Resources/config/validation/Block.xml @@ -38,9 +38,5 @@ - - - - diff --git a/src/Resources/config/validation/BlockTranslation.xml b/src/Resources/config/validation/BlockTranslation.xml deleted file mode 100644 index 61da5b5dd..000000000 --- a/src/Resources/config/validation/BlockTranslation.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - diff --git a/src/Resources/translations/messages.en.yml b/src/Resources/translations/messages.en.yml index 377eefe4b..cbb9c5059 100755 --- a/src/Resources/translations/messages.en.yml +++ b/src/Resources/translations/messages.en.yml @@ -62,3 +62,6 @@ bitbag_sylius_cms_plugin: publish_at: Publish at page_will_be_publish_at: This page will be publish at save_with_original_name: Save with original name + block_content: + type: + content_text: Text content diff --git a/src/Resources/views/Block/Crud/_form.html.twig b/src/Resources/views/Block/Crud/_form.html.twig index f6ed4db1e..28d213306 100755 --- a/src/Resources/views/Block/Crud/_form.html.twig +++ b/src/Resources/views/Block/Crud/_form.html.twig @@ -9,26 +9,21 @@ {{ form_row(form.name) }} {{ form_row(form.enabled) }} {{ form_row(form.channels) }} + {{ form_row(form.locales) }} {{ form_row(form.collections) }}
-
+

{{ 'sylius.ui.configuration'|trans }}

-
-
+
+
{{ form_row(form.contents) }}
- -
-
- {{ translationForm(form.translations, resource) }} -
-
From 67f1e7741c7f5fda8c0f8d374fed8cb94274d9e6 Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 25 Jun 2024 13:06:02 +0200 Subject: [PATCH 14/27] OP-321: Tests adjustments --- features/api/viewing_blocks.feature | 1 - spec/Entity/BlockTranslationSpec.php | 47 ---- spec/Importer/BlockImporterSpec.php | 38 +-- .../packages/bitbag_sylius_cms_plugin.yaml | 65 ----- tests/Behat/Context/Setup/BlockContext.php | 12 +- .../DataFixtures/ORM/Api/BlockTest/block.yml | 31 --- tests/Functional/Fixture/BlockFixtureTest.php | 248 ------------------ .../BlockTest/test_it_get_block_by_id.json | 18 +- .../Api/BlockTest/test_it_get_blocks.json | 44 +--- ...test_it_finds_block_by_collection_code.yml | 22 -- .../test_it_finds_block_by_product_code.yml | 29 -- .../Repository/BlockRepositoryTest.php | 17 +- 12 files changed, 21 insertions(+), 551 deletions(-) delete mode 100755 spec/Entity/BlockTranslationSpec.php diff --git a/features/api/viewing_blocks.feature b/features/api/viewing_blocks.feature index de2888844..c2453c011 100644 --- a/features/api/viewing_blocks.feature +++ b/features/api/viewing_blocks.feature @@ -19,5 +19,4 @@ Feature: Getting data from cms blocks Scenario: Displaying block Given I view block with code "block-1" Then I should see block name - And I should see block content diff --git a/spec/Entity/BlockTranslationSpec.php b/spec/Entity/BlockTranslationSpec.php deleted file mode 100755 index 2bc57c894..000000000 --- a/spec/Entity/BlockTranslationSpec.php +++ /dev/null @@ -1,47 +0,0 @@ -shouldHaveType(ResourceInterface::class); - } - - public function it_is_a_resource(): void - { - $this->shouldHaveType(ResourceInterface::class); - } - - public function it_implements_block_translation_interface(): void - { - $this->shouldHaveType(BlockTranslationInterface::class); - $this->shouldHaveType(TranslationInterface::class); - } - - public function it_allows_access_via_properties(): void - { - $this->setName('Escobar favorite quote'); - $this->getName()->shouldReturn('Escobar favorite quote'); - - $this->setLink('https://en.wikipedia.org/wiki/Pablo_Escobar'); - $this->getLink()->shouldReturn('https://en.wikipedia.org/wiki/Pablo_Escobar'); - - $this->setContent('Plata o plomo'); - $this->getContent()->shouldReturn('Plata o plomo'); - } -} diff --git a/spec/Importer/BlockImporterSpec.php b/spec/Importer/BlockImporterSpec.php index a5d5a3687..a4181fade 100644 --- a/spec/Importer/BlockImporterSpec.php +++ b/spec/Importer/BlockImporterSpec.php @@ -17,24 +17,21 @@ use BitBag\SyliusCmsPlugin\Resolver\ImporterCollectionsResolverInterface; use BitBag\SyliusCmsPlugin\Resolver\ResourceResolverInterface; use PhpSpec\ObjectBehavior; -use Sylius\Component\Locale\Context\LocaleContextInterface; use Symfony\Component\Validator\ConstraintViolationList; use Symfony\Component\Validator\Validator\ValidatorInterface; final class BlockImporterSpec extends ObjectBehavior { public function let( - ResourceResolverInterface $blockResourceResolver, - LocaleContextInterface $localeContext, + ResourceResolverInterface $blockResourceResolver, ImporterCollectionsResolverInterface $importerCollectionsResolver, - ImporterChannelsResolverInterface $importerChannelsResolver, - ImporterProductsResolverInterface $importerProductsResolver, - ValidatorInterface $validator, - BlockRepositoryInterface $blockRepository + ImporterChannelsResolverInterface $importerChannelsResolver, + ImporterProductsResolverInterface $importerProductsResolver, + ValidatorInterface $validator, + BlockRepositoryInterface $blockRepository ) { $this->beConstructedWith( $blockResourceResolver, - $localeContext, $importerCollectionsResolver, $importerChannelsResolver, $importerProductsResolver, @@ -50,28 +47,19 @@ public function it_is_initializable() } public function it_imports_block( - ResourceResolverInterface $blockResourceResolver, - LocaleContextInterface $localeContext, + ResourceResolverInterface $blockResourceResolver, ImporterCollectionsResolverInterface $importerCollectionsResolver, - ImporterChannelsResolverInterface $importerChannelsResolver, - ImporterProductsResolverInterface $importerProductsResolver, - ValidatorInterface $validator, - BlockRepositoryInterface $blockRepository, - BlockInterface $block - ) - { - $row = ['name_pl' => 'name', 'content_pl' => 'content', 'link_pl' => 'link', 'code' => 'block_code']; + ImporterChannelsResolverInterface $importerChannelsResolver, + ImporterProductsResolverInterface $importerProductsResolver, + ValidatorInterface $validator, + BlockRepositoryInterface $blockRepository, + BlockInterface $block + ) { + $row = ['name_pl' => 'name', 'code' => 'block_code']; $blockResourceResolver->getResource('block_code')->willReturn($block); - $localeContext->getLocaleCode()->willReturn('en_US'); - $block->setCode('block_code')->shouldBeCalled(); - $block->setFallbackLocale('en_US')->shouldBeCalled(); - $block->setCurrentLocale('pl')->shouldBeCalled(); - $block->setName('name')->shouldBeCalled(); - $block->setLink('link')->shouldBeCalled(); - $block->setContent('content')->shouldBeCalled(); $importerCollectionsResolver->resolve($block, null)->shouldBeCalled(); $importerChannelsResolver->resolve($block, null)->shouldBeCalled(); diff --git a/tests/Application/config/packages/bitbag_sylius_cms_plugin.yaml b/tests/Application/config/packages/bitbag_sylius_cms_plugin.yaml index e3f397167..423efca8b 100644 --- a/tests/Application/config/packages/bitbag_sylius_cms_plugin.yaml +++ b/tests/Application/config/packages/bitbag_sylius_cms_plugin.yaml @@ -40,90 +40,25 @@ sylius_fixtures: homepage_products_info: channels: - "FASHION_WEB" - translations: - en_US: - content: | -
- Click one of the below products to see what you can do with the blocks in your product view! -
collection_info_block: channels: - "FASHION_WEB" collections: - "products" - translations: - en_US: - content: | -
- The block you can see on the left is just a block associated with a collection named Products -
-

With this feature, you can render any block you want on the product page, like size table, delivery information, or even promotion banner.

-

It's done with a simple controller render:

-
{{ render(path('bitbag_sylius_cms_plugin_shop_block_index_by_collection_code', {'collectionCode' : 'products', 'template' : '@BitBagSyliusCmsPlugin/Shop/Block/index.html.twig'})) }}
product_info_block: channels: - "FASHION_WEB" - products: 5 - translations: - en_US: - content: | -
On the other hand, the block on the right is a block associated with specific products.
-

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

-

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

-
{{ render(path('bitbag_sylius_cms_plugin_shop_block_index_by_product_code', {'productCode' : product.code, 'template' : '@BitBagSyliusCmsPlugin/Shop/Block/index.html.twig'})) }}
homepage_intro: channels: - "FASHION_WEB" - translations: - en_US: - content: | -

Blocks

-

- The left block is rendered with the usage of the particular controller like this: -

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

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

-

- The other three blocks, including this one you are reading right now, are using Twig helper method. -

- -
-                                            bitbag_cms_render_block('homepage_intro')
-                                            bitbag_cms_render_block('homepage_banner_image_1')
-                                            bitbag_cms_render_block('homepage_banner_image_2')
-                                            
lorem_ipsum: channels: - "FASHION_WEB" collections: - "homepage" - translations: - en_US: - content: | -

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus

-
    -
  • Morbi in sem quis dui placerat ornare. Pellentesque odio nisi, euismod in, pharetra a, ultricies in, diam. Sed arcu. Cras consequat.
  • -
  • Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus.
  • -
  • Phasellus ultrices nulla quis nibh. Quisque a lectus. Donec consectetuer ligula vulputate sem tristique cursus. Nam nulla quam, gravida non, commodo a, sodales sit amet, nisi.
  • -
  • Pellentesque fermentum dolor. Aliquam quam lectus, facilisis auctor, ultrices ut, elementum vulputate, nunc.
  • -
-

Pellentesque habitant morbi tristique sene

taxons_and_products_block: channels: - "FASHION_WEB" - productCodes: - - "666F_boyfriend_jeans_with_rips" - - "727F_patched_cropped_jeans" - - "111F_patched_jeans_with_fancy_badges" - taxons: - - "womens_jeans" - translations: - en_US: - name: "Womens jeans" media: options: custom: diff --git a/tests/Behat/Context/Setup/BlockContext.php b/tests/Behat/Context/Setup/BlockContext.php index 0d25adb70..f351f9bd8 100755 --- a/tests/Behat/Context/Setup/BlockContext.php +++ b/tests/Behat/Context/Setup/BlockContext.php @@ -52,23 +52,20 @@ public function thereIsABlockWithCode(string $code): void /** * @Given there is a block with :code code and :content content */ - public function thereIsABlockWithCodeAndContent(string $code, string $content): void + public function thereIsABlockWithCodeAndContent(string $code): void { - $block = $this->createBlock($code, $content); + $block = $this->createBlock($code); $this->saveBlock($block); } private function createBlock( ?string $code = null, - ?string $content = null, ChannelInterface $channel = null, ): BlockInterface { /** @var BlockInterface $block */ $block = $this->blockFactory->createNew(); - $block->setCurrentLocale('en_US'); - if (null === $channel && $this->sharedStorage->has('channel')) { $channel = $this->sharedStorage->get('channel'); } @@ -77,12 +74,7 @@ private function createBlock( $code = $this->randomStringGenerator->generate(); } - if (null === $content) { - $content = $this->randomStringGenerator->generate(); - } - $block->setCode($code); - $block->setContent($content); $block->addChannel($channel); return $block; diff --git a/tests/Functional/DataFixtures/ORM/Api/BlockTest/block.yml b/tests/Functional/DataFixtures/ORM/Api/BlockTest/block.yml index 67e66abd9..1ea8738e4 100644 --- a/tests/Functional/DataFixtures/ORM/Api/BlockTest/block.yml +++ b/tests/Functional/DataFixtures/ORM/Api/BlockTest/block.yml @@ -71,59 +71,28 @@ Sylius\Component\Core\Model\ProductVariant: product_variant1: product: '@product1' code: "code1" - -BitBag\SyliusCmsPlugin\Entity\BlockTranslation: - block1_translation: - name: 'translation_name_en_US' - locale: 'en_US' - content: 'translation_content_en_US' - link: 'translation_link_en_US' - block2_translation: - name: 'translation_name_en_US' - locale: 'en_US' - content: 'translation_content_en_US' - link: 'translation_link_en_US' - block3_translation: - name: 'translation_name_en_US' - locale: 'en_US' - content: 'translation_content_en_US' - link: 'translation_link_en_US' BitBag\SyliusCmsPlugin\Entity\Block: block1: code: 'block1-code' enabled: true - products: - - '@product1' collections: - '@collection1' channels: - '@channel' - translations: - - '@block1_translation' - taxons: - - '@taxon' block2: code: 'block2-code' enabled: true - products: - - '@product2' collections: - '@collection2' channels: - '@channel' - translations: - - '@block2_translation' block3: code: 'block3-code' enabled: false - products: - - '@product3' collections: - '@collection3' channels: - '@channel' - translations: - - '@block3_translation' BitBag\SyliusCmsPlugin\Entity\Collection: collection1: code: 'collection1-code' diff --git a/tests/Functional/Fixture/BlockFixtureTest.php b/tests/Functional/Fixture/BlockFixtureTest.php index 6916a941d..17e936ad9 100644 --- a/tests/Functional/Fixture/BlockFixtureTest.php +++ b/tests/Functional/Fixture/BlockFixtureTest.php @@ -105,118 +105,6 @@ public function custom_number_is_optional_but_must_be_integer(): void ], 'custom.*.number'); } - /** - * @test - */ - public function custom_last_four_products_is_optional_but_must_be_boolean(): void - { - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'last_four_products' => true, - ], - ], - ], - ], 'custom.*.last_four_products'); - - $this->assertPartialConfigurationIsInvalid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'last_four_products' => 'boolean', - ], - ], - ], - ], 'custom.*.last_four_products'); - } - - /** - * @test - */ - public function custom_products_is_optional_but_must_be_integer(): void - { - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'products' => 5, - ], - ], - ], - ], 'custom.*.products'); - - $this->assertPartialConfigurationIsInvalid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'enabled' => 'integer', - ], - ], - ], - ], 'custom.*.products'); - } - - /** - * @test - */ - public function custom_product_codes_is_optional_but_must_be_array(): void - { - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'productCodes' => [], - ], - ], - ], - ], 'custom.*.productCodes'); - - $this->assertPartialConfigurationIsInvalid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'enabled' => 'integer', - ], - ], - ], - ], 'custom.*.productCodes'); - } - - /** - * @test - */ - public function custom_translations_is_optional_but_must_be_array(): void - { - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'translations' => [], - ], - ], - ], - ], 'custom.*.translations'); - - $this->assertPartialConfigurationIsInvalid([ - [ - 'custom' => [ - 'custom_1' => [ - 'translations' => '', - ], - ], - ], - ], 'custom.*.translations'); - - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'custom_1' => [], - ], - ], - ], 'custom.*.translations'); - } - /** * @test */ @@ -263,142 +151,6 @@ public function custom_collections_is_optional_but_must_be_scalar_array(): void ], 'custom.*.collections'); } - /** - * @test - */ - public function custom_may_contain_name(): void - { - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'translations' => [ - 'en_US' => [ - 'name' => 'block', - ], - ], - ], - ], - ], - ], 'custom.*.translations.*.name'); - - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'translations' => [ - 'en_US' => [ - 'name' => '', - ], - ], - ], - ], - ], - ], 'custom.*.translations.*.name'); - } - - /** - * @test - */ - public function custom_may_contain_content(): void - { - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'translations' => [ - 'en_US' => [ - 'content' => 'block', - ], - ], - ], - ], - ], - ], 'custom.*.translations.*.content'); - - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'translations' => [ - 'en_US' => [ - 'content' => '', - ], - ], - ], - ], - ], - ], 'custom.*.translations.*.content'); - } - - /** - * @test - */ - public function custom_may_contain_link(): void - { - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'translations' => [ - 'en_US' => [ - 'link' => 'block', - ], - ], - ], - ], - ], - ], 'custom.*.translations.*.link'); - - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'translations' => [ - 'en_US' => [ - 'link' => '', - ], - ], - ], - ], - ], - ], 'custom.*.translations.*.link'); - } - - /** - * @test - */ - public function custom_may_contain_image_path(): void - { - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'translations' => [ - 'en_US' => [ - 'image_path' => '/path/to/img', - ], - ], - ], - ], - ], - ], 'custom.*.translations.*.image_path'); - - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'translations' => [ - 'en_US' => [ - 'image_path' => '', - ], - ], - ], - ], - ], - ], 'custom.*.translations.*.image_path'); - } - protected function getConfiguration(): BlockFixture { /** @var FixtureFactoryInterface $blockFixtureFactory */ diff --git a/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_block_by_id.json b/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_block_by_id.json index d4442784c..18560fbd8 100644 --- a/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_block_by_id.json +++ b/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_block_by_id.json @@ -13,24 +13,8 @@ "code": "collection1-code" } ], - "products": [ - "/api/v2/shop/products/MUG_SW" - ], "channels": [ "/api/v2/shop/channels/code" ], - "translations": { - "en_US": { - "@type": "BlockTranslation", - "name": "translation_name_en_US", - "content": "translation_content_en_US", - "link": "translation_link_en_US" - } - }, - "taxons": [ - { - "@id": "/api/v2/shop/taxons/menu_category", - "@type": "Taxon" - } - ] + "contents": [] } diff --git a/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_blocks.json b/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_blocks.json index 9a8d02cfb..7fa2cd847 100644 --- a/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_blocks.json +++ b/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_blocks.json @@ -17,26 +17,10 @@ "code": "collection1-code" } ], - "products": [ - "/api/v2/shop/products/MUG_SW" - ], "channels": [ "/api/v2/shop/channels/code" ], - "translations": { - "en_US": { - "@type": "BlockTranslation", - "name": "translation_name_en_US", - "content": "translation_content_en_US", - "link": "translation_link_en_US" - } - }, - "taxons": [ - { - "@id": "/api/v2/shop/taxons/menu_category", - "@type": "Taxon" - } - ] + "contents": [] }, { "@id": "/api/v2/shop/cms-plugin/blocks/@integer@", @@ -52,21 +36,10 @@ "code": "collection2-code" } ], - "products": [ - "/api/v2/shop/products/MUG_SW2" - ], "channels": [ "/api/v2/shop/channels/code" ], - "translations": { - "en_US": { - "@type": "BlockTranslation", - "name": "translation_name_en_US", - "content": "translation_content_en_US", - "link": "translation_link_en_US" - } - }, - "taxons": [] + "contents": [] }, { "@id": "/api/v2/shop/cms-plugin/blocks/@integer@", @@ -82,21 +55,10 @@ "code": "collection3-code" } ], - "products": [ - "/api/v2/shop/products/MUG_SW3" - ], "channels": [ "/api/v2/shop/channels/code" ], - "translations": { - "en_US": { - "@type": "BlockTranslation", - "name": "translation_name_en_US", - "content": "translation_content_en_US", - "link": "translation_link_en_US" - } - }, - "taxons": [] + "contents": [] } ], "hydra:totalItems": 3 diff --git a/tests/Integration/DataFixtures/ORM/BlockRepositoryTest/test_it_finds_block_by_collection_code.yml b/tests/Integration/DataFixtures/ORM/BlockRepositoryTest/test_it_finds_block_by_collection_code.yml index 61f111d7f..8e4fb1b0c 100644 --- a/tests/Integration/DataFixtures/ORM/BlockRepositoryTest/test_it_finds_block_by_collection_code.yml +++ b/tests/Integration/DataFixtures/ORM/BlockRepositoryTest/test_it_finds_block_by_collection_code.yml @@ -17,22 +17,6 @@ Sylius\Component\Core\Model\Channel: default_locale: '@locale' tax_calculation_strategy: 'order_items_based' base_currency: '@dollar' -BitBag\SyliusCmsPlugin\Entity\BlockTranslation: - block1_translation: - name: 'translation_name_en_US' - locale: 'en_US' - content: 'translation_content_en_US' - link: 'translation_link_en_US' - block2_translation: - name: 'translation_name_en_US' - locale: 'en_US' - content: 'translation_content_en_US' - link: 'translation_link_en_US' - block3_translation: - name: 'translation_name_en_US' - locale: 'en_US' - content: 'translation_content_en_US' - link: 'translation_link_en_US' BitBag\SyliusCmsPlugin\Entity\Block: block1: code: 'block1-code' @@ -41,8 +25,6 @@ BitBag\SyliusCmsPlugin\Entity\Block: - '@collection1' channels: - '@channel' - translations: - - '@block1_translation' block2: code: 'block2-code' enabled: true @@ -50,8 +32,6 @@ BitBag\SyliusCmsPlugin\Entity\Block: - '@collection2' channels: - '@channel' - translations: - - '@block2_translation' block3: code: 'block3-code' enabled: false @@ -59,8 +39,6 @@ BitBag\SyliusCmsPlugin\Entity\Block: - '@collection3' channels: - '@channel' - translations: - - '@block3_translation' BitBag\SyliusCmsPlugin\Entity\Collection: collection1: code: 'collection1-code' diff --git a/tests/Integration/DataFixtures/ORM/BlockRepositoryTest/test_it_finds_block_by_product_code.yml b/tests/Integration/DataFixtures/ORM/BlockRepositoryTest/test_it_finds_block_by_product_code.yml index b59eb71e9..1ea8738e4 100644 --- a/tests/Integration/DataFixtures/ORM/BlockRepositoryTest/test_it_finds_block_by_product_code.yml +++ b/tests/Integration/DataFixtures/ORM/BlockRepositoryTest/test_it_finds_block_by_product_code.yml @@ -71,57 +71,28 @@ Sylius\Component\Core\Model\ProductVariant: product_variant1: product: '@product1' code: "code1" - -BitBag\SyliusCmsPlugin\Entity\BlockTranslation: - block1_translation: - name: 'translation_name_en_US' - locale: 'en_US' - content: 'translation_content_en_US' - link: 'translation_link_en_US' - block2_translation: - name: 'translation_name_en_US' - locale: 'en_US' - content: 'translation_content_en_US' - link: 'translation_link_en_US' - block3_translation: - name: 'translation_name_en_US' - locale: 'en_US' - content: 'translation_content_en_US' - link: 'translation_link_en_US' BitBag\SyliusCmsPlugin\Entity\Block: block1: code: 'block1-code' enabled: true - products: - - '@product1' collections: - '@collection1' channels: - '@channel' - translations: - - '@block1_translation' block2: code: 'block2-code' enabled: true - products: - - '@product2' collections: - '@collection2' channels: - '@channel' - translations: - - '@block2_translation' block3: code: 'block3-code' enabled: false - products: - - '@product3' collections: - '@collection3' channels: - '@channel' - translations: - - '@block3_translation' BitBag\SyliusCmsPlugin\Entity\Collection: collection1: code: 'collection1-code' diff --git a/tests/Integration/Repository/BlockRepositoryTest.php b/tests/Integration/Repository/BlockRepositoryTest.php index f9bd8084a..a76f67933 100644 --- a/tests/Integration/Repository/BlockRepositoryTest.php +++ b/tests/Integration/Repository/BlockRepositoryTest.php @@ -41,21 +41,8 @@ public function test_it_finds_enabled_block_by_collection_code(): void $blockRepository = $this->getRepository(); - $block_array1 = $blockRepository->findByCollectionCode('collection1-code', 'en_US', 'code'); - $block_array3 = $blockRepository->findByCollectionCode('collection3-code', 'en_US', 'code'); - - self::assertNotEmpty($block_array1); - self::assertEmpty($block_array3); - } - - public function test_it_finds_enabled_block_by_product_code(): void - { - $this->loadFixturesFromFile('BlockRepositoryTest/test_it_finds_block_by_product_code.yml'); - - $blockRepository = $this->getRepository(); - - $block_array1 = $blockRepository->findByProductCode('MUG_SW', 'en_US', 'code'); - $block_array3 = $blockRepository->findByProductCode('MUG_SW3', 'en_US', 'code'); + $block_array1 = $blockRepository->findByCollectionCode('collection1-code', 'code'); + $block_array3 = $blockRepository->findByCollectionCode('collection3-code', 'code'); self::assertNotEmpty($block_array1); self::assertEmpty($block_array3); From 6c2d40930201d0f4f65c12b1cebca556e0d3c26a Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 25 Jun 2024 13:10:14 +0200 Subject: [PATCH 15/27] OP-321: PHPStan fix --- src/Importer/BlockImporter.php | 2 -- src/Resources/config/services/importer.xml | 1 - 2 files changed, 3 deletions(-) diff --git a/src/Importer/BlockImporter.php b/src/Importer/BlockImporter.php index d483de097..f2023280d 100644 --- a/src/Importer/BlockImporter.php +++ b/src/Importer/BlockImporter.php @@ -25,7 +25,6 @@ public function __construct( private ResourceResolverInterface $blockResourceResolver, private ImporterCollectionsResolverInterface $importerCollectionsResolver, private ImporterChannelsResolverInterface $importerChannelsResolver, - private ImporterProductsResolverInterface $importerProductsResolver, ValidatorInterface $validator, private BlockRepositoryInterface $blockRepository, ) { @@ -43,7 +42,6 @@ public function import(array $row): void $this->importerCollectionsResolver->resolve($block, $this->getColumnValue(self::COLLECTIONS_COLUMN, $row)); $this->importerChannelsResolver->resolve($block, $this->getColumnValue(self::CHANNELS_COLUMN, $row)); - $this->importerProductsResolver->resolve($block, $this->getColumnValue(self::PRODUCTS_COLUMN, $row)); $this->validateResource($block, ['bitbag']); $this->blockRepository->add($block); diff --git a/src/Resources/config/services/importer.xml b/src/Resources/config/services/importer.xml index 5903792b1..2857f77a6 100644 --- a/src/Resources/config/services/importer.xml +++ b/src/Resources/config/services/importer.xml @@ -24,7 +24,6 @@ - From 927944ca8d7902b03e1ebff99ade2223b081adf5 Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 25 Jun 2024 13:12:16 +0200 Subject: [PATCH 16/27] OP-321: ECS auto fix --- src/Entity/BlockContent.php | 8 ++++---- src/Entity/LocaleAwareInterface.php | 1 - src/Entity/LocaleAwareTrait.php | 1 - src/Form/Type/BlockContentType.php | 4 ++-- src/Form/Type/BlockType.php | 2 +- src/Importer/BlockImporter.php | 1 - src/Repository/BlockRepositoryInterface.php | 1 - 7 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/Entity/BlockContent.php b/src/Entity/BlockContent.php index b0db2f7b8..7a4519240 100644 --- a/src/Entity/BlockContent.php +++ b/src/Entity/BlockContent.php @@ -12,13 +12,13 @@ final class BlockContent implements BlockContentInterface { - protected ?int $id; + private ?int $id; - protected ?string $type; + private ?string $type; - protected array $configuration = []; + private array $configuration = []; - protected ?BlockInterface $block = null; + private ?BlockInterface $block = null; public function getId(): ?int { diff --git a/src/Entity/LocaleAwareInterface.php b/src/Entity/LocaleAwareInterface.php index 80d4aeefe..0cd3117e2 100644 --- a/src/Entity/LocaleAwareInterface.php +++ b/src/Entity/LocaleAwareInterface.php @@ -6,7 +6,6 @@ * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career */ - declare(strict_types=1); namespace BitBag\SyliusCmsPlugin\Entity; diff --git a/src/Entity/LocaleAwareTrait.php b/src/Entity/LocaleAwareTrait.php index 9ba37728b..14215f584 100644 --- a/src/Entity/LocaleAwareTrait.php +++ b/src/Entity/LocaleAwareTrait.php @@ -6,7 +6,6 @@ * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career */ - declare(strict_types=1); namespace BitBag\SyliusCmsPlugin\Entity; diff --git a/src/Form/Type/BlockContentType.php b/src/Form/Type/BlockContentType.php index c4296b1c2..3b50456a2 100644 --- a/src/Form/Type/BlockContentType.php +++ b/src/Form/Type/BlockContentType.php @@ -65,7 +65,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $form = $event->getForm(); $formData = $form->getData(); - if ($formData !== null && $formData->getType() !== $data['type']) { + if (null !== $formData && $formData->getType() !== $data['type']) { $formData->setConfiguration([]); } @@ -77,7 +77,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void private function addConfigurationTypeToForm(FormEvent $event): void { $data = $event->getData(); - if ($data === null) { + if (null === $data) { return; } diff --git a/src/Form/Type/BlockType.php b/src/Form/Type/BlockType.php index b723c9a7d..588df0666 100755 --- a/src/Form/Type/BlockType.php +++ b/src/Form/Type/BlockType.php @@ -14,9 +14,9 @@ use Sylius\Bundle\ChannelBundle\Form\Type\ChannelChoiceType; use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; +use Symfony\Component\Form\Extension\Core\Type\CollectionType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\Form\Extension\Core\Type\CollectionType; final class BlockType extends AbstractResourceType { diff --git a/src/Importer/BlockImporter.php b/src/Importer/BlockImporter.php index f2023280d..5261460fb 100644 --- a/src/Importer/BlockImporter.php +++ b/src/Importer/BlockImporter.php @@ -14,7 +14,6 @@ use BitBag\SyliusCmsPlugin\Repository\BlockRepositoryInterface; use BitBag\SyliusCmsPlugin\Resolver\ImporterChannelsResolverInterface; use BitBag\SyliusCmsPlugin\Resolver\ImporterCollectionsResolverInterface; -use BitBag\SyliusCmsPlugin\Resolver\ImporterProductsResolverInterface; use BitBag\SyliusCmsPlugin\Resolver\ResourceResolverInterface; use Symfony\Component\Validator\Validator\ValidatorInterface; use Webmozart\Assert\Assert; diff --git a/src/Repository/BlockRepositoryInterface.php b/src/Repository/BlockRepositoryInterface.php index 2ff20d720..6ea8534d1 100755 --- a/src/Repository/BlockRepositoryInterface.php +++ b/src/Repository/BlockRepositoryInterface.php @@ -11,7 +11,6 @@ namespace BitBag\SyliusCmsPlugin\Repository; use BitBag\SyliusCmsPlugin\Entity\BlockInterface; -use Doctrine\ORM\QueryBuilder; use Sylius\Component\Resource\Repository\RepositoryInterface; interface BlockRepositoryInterface extends RepositoryInterface From 41ee7c1f661109e2ab8c3cadb95094853610e269 Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 25 Jun 2024 13:50:51 +0200 Subject: [PATCH 17/27] OP-321: Removed final word from BlockContent.php --- src/Entity/BlockContent.php | 10 +++++----- src/Entity/BlockContentInterface.php | 2 -- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Entity/BlockContent.php b/src/Entity/BlockContent.php index 7a4519240..dd0d3fe65 100644 --- a/src/Entity/BlockContent.php +++ b/src/Entity/BlockContent.php @@ -10,15 +10,15 @@ namespace BitBag\SyliusCmsPlugin\Entity; -final class BlockContent implements BlockContentInterface +class BlockContent implements BlockContentInterface { - private ?int $id; + protected ?int $id; - private ?string $type; + protected ?string $type; - private array $configuration = []; + protected array $configuration = []; - private ?BlockInterface $block = null; + protected ?BlockInterface $block = null; public function getId(): ?int { diff --git a/src/Entity/BlockContentInterface.php b/src/Entity/BlockContentInterface.php index 952e9552b..a993a3b75 100644 --- a/src/Entity/BlockContentInterface.php +++ b/src/Entity/BlockContentInterface.php @@ -14,8 +14,6 @@ interface BlockContentInterface extends ResourceInterface { - public function getId(): ?int; - public function getType(): ?string; public function setType(?string $type): void; From 72e59c0fd0daa9aa9d3e6b449e0dca4baacecfe2 Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 25 Jun 2024 13:54:24 +0200 Subject: [PATCH 18/27] OP-321: Remove wrong migration --- src/Migrations/Version20240621093611.php | 37 ------------------------ 1 file changed, 37 deletions(-) delete mode 100644 src/Migrations/Version20240621093611.php diff --git a/src/Migrations/Version20240621093611.php b/src/Migrations/Version20240621093611.php deleted file mode 100644 index 8eab82fed..000000000 --- a/src/Migrations/Version20240621093611.php +++ /dev/null @@ -1,37 +0,0 @@ -addSql('CREATE TABLE bitbag_cms_block_content (id INT AUTO_INCREMENT NOT NULL, block_id INT DEFAULT NULL, type VARCHAR(255) NOT NULL, configuration JSON NOT NULL COMMENT \'(DC2Type:json)\', INDEX IDX_FAA763A8E9ED820C (block_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('ALTER TABLE bitbag_cms_block_content ADD CONSTRAINT FK_FAA763A8E9ED820C FOREIGN KEY (block_id) REFERENCES bitbag_cms_block (id)'); - $this->addSql('ALTER TABLE bitbag_cms_block ADD name VARCHAR(250) DEFAULT NULL'); - $this->addSql('ALTER TABLE bitbag_cms_block_translation DROP name, DROP link'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE bitbag_cms_block_content DROP FOREIGN KEY FK_FAA763A8E9ED820C'); - $this->addSql('DROP TABLE bitbag_cms_block_content'); - $this->addSql('ALTER TABLE bitbag_cms_block_translation ADD name VARCHAR(255) DEFAULT NULL, ADD link LONGTEXT DEFAULT NULL'); - $this->addSql('ALTER TABLE bitbag_cms_block DROP name'); - } -} From 114fe666dae5069d31a62bd6abd7002d11840d8d Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 25 Jun 2024 14:08:59 +0200 Subject: [PATCH 19/27] OP-321: Spec fix --- spec/Entity/BlockSpec.php | 24 ------------------------ spec/Importer/BlockImporterSpec.php | 4 ---- 2 files changed, 28 deletions(-) diff --git a/spec/Entity/BlockSpec.php b/spec/Entity/BlockSpec.php index 988f87756..190db4c18 100755 --- a/spec/Entity/BlockSpec.php +++ b/spec/Entity/BlockSpec.php @@ -45,18 +45,6 @@ public function it_toggles(): void $this->isEnabled()->shouldReturn(false); } - public function it_associates_products(ProductInterface $firstProduct, ProductInterface $secondProduct): void - { - $this->addProduct($firstProduct); - $this->hasProduct($firstProduct)->shouldReturn(true); - - $this->hasProduct($secondProduct)->shouldReturn(false); - - $this->removeProduct($firstProduct); - - $this->hasProduct($firstProduct)->shouldReturn(false); - } - public function it_associates_collections(CollectionInterface $firstCollection, CollectionInterface $secondCollection): void { $this->addCollection($firstCollection); @@ -80,16 +68,4 @@ public function it_associates_channels(ChannelInterface $firstChannel, ChannelIn $this->hasChannel($firstChannel)->shouldReturn(false); } - - public function it_associates_taxons(TaxonInterface $firstTaxon, TaxonInterface $secondTaxon): void - { - $this->addTaxon($firstTaxon); - $this->hasTaxon($firstTaxon)->shouldReturn(true); - - $this->hasTaxon($secondTaxon)->shouldReturn(false); - - $this->removeTaxon($firstTaxon); - - $this->hasTaxon($secondTaxon)->shouldReturn(false); - } } diff --git a/spec/Importer/BlockImporterSpec.php b/spec/Importer/BlockImporterSpec.php index a4181fade..cf4a53529 100644 --- a/spec/Importer/BlockImporterSpec.php +++ b/spec/Importer/BlockImporterSpec.php @@ -26,7 +26,6 @@ public function let( ResourceResolverInterface $blockResourceResolver, ImporterCollectionsResolverInterface $importerCollectionsResolver, ImporterChannelsResolverInterface $importerChannelsResolver, - ImporterProductsResolverInterface $importerProductsResolver, ValidatorInterface $validator, BlockRepositoryInterface $blockRepository ) { @@ -34,7 +33,6 @@ public function let( $blockResourceResolver, $importerCollectionsResolver, $importerChannelsResolver, - $importerProductsResolver, $validator, $blockRepository ); @@ -50,7 +48,6 @@ public function it_imports_block( ResourceResolverInterface $blockResourceResolver, ImporterCollectionsResolverInterface $importerCollectionsResolver, ImporterChannelsResolverInterface $importerChannelsResolver, - ImporterProductsResolverInterface $importerProductsResolver, ValidatorInterface $validator, BlockRepositoryInterface $blockRepository, BlockInterface $block @@ -63,7 +60,6 @@ public function it_imports_block( $importerCollectionsResolver->resolve($block, null)->shouldBeCalled(); $importerChannelsResolver->resolve($block, null)->shouldBeCalled(); - $importerProductsResolver->resolve($block, null)->shouldBeCalled(); $validator->validate($block, null, ['bitbag'])->willReturn(new ConstraintViolationList()); From 98b1a88c1e06f87c2fc38a4d0aac183fe94be221 Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 25 Jun 2024 14:47:51 +0200 Subject: [PATCH 20/27] OP-321: Behat fix and homepage render fix --- features/admin/adding_block.feature | 4 +--- features/admin/managing_blocks.feature | 2 +- src/Entity/Block.php | 7 +++++++ src/Entity/BlockInterface.php | 3 ++- tests/Behat/Context/Setup/BlockContext.php | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/features/admin/adding_block.feature b/features/admin/adding_block.feature index b133db9c3..93aa26346 100644 --- a/features/admin/adding_block.feature +++ b/features/admin/adding_block.feature @@ -12,7 +12,6 @@ Feature: Adding blocks Scenario: Adding block When I go to the create block page And I fill the code with "store_description" - And I fill the content with "

We have the best candies on the internet!

" And I add it Then I should be notified that the block has been created @@ -22,7 +21,6 @@ Feature: Adding blocks When I go to the create block page And I fill the code with "intro" And I add "Blog" and "Homepage" collections to it - And I fill the content with "Hello world!" And I add it Then I should be notified that the block has been created @@ -43,7 +41,7 @@ Feature: Adding blocks @ui Scenario: Trying to add block with too long data When I go to the create block page - And I fill "Code, Name, Content" fields with 251 characters + And I fill "Code, Name" fields with 251 characters And I try to add it Then I should be notified that "Code, Name" fields are too long diff --git a/features/admin/managing_blocks.feature b/features/admin/managing_blocks.feature index 22c4b0a44..c08e7eac4 100644 --- a/features/admin/managing_blocks.feature +++ b/features/admin/managing_blocks.feature @@ -18,7 +18,7 @@ Feature: Managing cms blocks @ui @javascript Scenario: Updating block - Given there is a block with "store_phone_number" code and "123456789" content + Given there is a block with "store_phone_number" code When I go to the update "store_phone_number" block page And I fill the content with "987654321" And I update it diff --git a/src/Entity/Block.php b/src/Entity/Block.php index d03f63024..0ed71c181 100755 --- a/src/Entity/Block.php +++ b/src/Entity/Block.php @@ -58,4 +58,11 @@ public function setName(?string $name): void { $this->name = $name; } + + public function getContent(): ?string + { + // TODO: empty for now for testing purposes, to be implemented in the future tasks + // related to the epic: https://bitbag.atlassian.net/browse/OP-312 + return ''; + } } diff --git a/src/Entity/BlockInterface.php b/src/Entity/BlockInterface.php index 562cc76bb..7401581f0 100755 --- a/src/Entity/BlockInterface.php +++ b/src/Entity/BlockInterface.php @@ -20,7 +20,8 @@ interface BlockInterface extends CollectionableInterface, ChannelsAwareInterface, BlockContentAwareInterface, - LocaleAwareInterface + LocaleAwareInterface, + ContentableInterface { public function getCode(): ?string; diff --git a/tests/Behat/Context/Setup/BlockContext.php b/tests/Behat/Context/Setup/BlockContext.php index f351f9bd8..29885340c 100755 --- a/tests/Behat/Context/Setup/BlockContext.php +++ b/tests/Behat/Context/Setup/BlockContext.php @@ -50,7 +50,7 @@ public function thereIsABlockWithCode(string $code): void } /** - * @Given there is a block with :code code and :content content + * @Given there is a block with :code code */ public function thereIsABlockWithCodeAndContent(string $code): void { From 2a8c56e8a25dcb6e0f6020af4d0bd110b2d9500d Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 25 Jun 2024 14:59:42 +0200 Subject: [PATCH 21/27] OP-321: Behat fix and block name vlaidator --- features/admin/managing_blocks.feature | 1 - src/Resources/config/validation/Block.xml | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/features/admin/managing_blocks.feature b/features/admin/managing_blocks.feature index c08e7eac4..6b4241137 100644 --- a/features/admin/managing_blocks.feature +++ b/features/admin/managing_blocks.feature @@ -20,7 +20,6 @@ Feature: Managing cms blocks Scenario: Updating block Given there is a block with "store_phone_number" code When I go to the update "store_phone_number" block page - And I fill the content with "987654321" And I update it Then I should be notified that the block has been successfully updated diff --git a/src/Resources/config/validation/Block.xml b/src/Resources/config/validation/Block.xml index 94148725d..272b1ee50 100644 --- a/src/Resources/config/validation/Block.xml +++ b/src/Resources/config/validation/Block.xml @@ -38,5 +38,22 @@ + + + + + + + + + + + + + From 9ddedba4a2d3fcd2c039cb65be426b4c992900c5 Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 25 Jun 2024 15:05:24 +0200 Subject: [PATCH 22/27] OP-321: Translations --- src/Resources/translations/messages.cs.yml | 3 +++ src/Resources/translations/messages.cs_CZ.yml | 3 +++ src/Resources/translations/messages.de.yml | 3 +++ src/Resources/translations/messages.es.yml | 3 +++ src/Resources/translations/messages.fr.yml | 3 +++ src/Resources/translations/messages.hr.yml | 3 +++ src/Resources/translations/messages.lt.yml | 4 +++- src/Resources/translations/messages.nl.yml | 3 +++ src/Resources/translations/messages.pl.yml | 3 +++ src/Resources/translations/messages.ru.yml | 3 +++ src/Resources/translations/messages.sk.yml | 3 +++ src/Resources/translations/messages.uk.yml | 3 +++ 12 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/Resources/translations/messages.cs.yml b/src/Resources/translations/messages.cs.yml index ba4cbd5c1..a7472163e 100755 --- a/src/Resources/translations/messages.cs.yml +++ b/src/Resources/translations/messages.cs.yml @@ -6,6 +6,9 @@ bitbag_sylius_cms_plugin: pages: Stránky page: Stránka title: Titul + block_content: + type: + content_text: Text cms: content_management: Obsahový management cms: Obsahový management diff --git a/src/Resources/translations/messages.cs_CZ.yml b/src/Resources/translations/messages.cs_CZ.yml index ba4cbd5c1..a7472163e 100755 --- a/src/Resources/translations/messages.cs_CZ.yml +++ b/src/Resources/translations/messages.cs_CZ.yml @@ -6,6 +6,9 @@ bitbag_sylius_cms_plugin: pages: Stránky page: Stránka title: Titul + block_content: + type: + content_text: Text cms: content_management: Obsahový management cms: Obsahový management diff --git a/src/Resources/translations/messages.de.yml b/src/Resources/translations/messages.de.yml index 3d16cb13c..d79c026de 100755 --- a/src/Resources/translations/messages.de.yml +++ b/src/Resources/translations/messages.de.yml @@ -56,3 +56,6 @@ bitbag_sylius_cms_plugin: import: Importieren successfully_imported: Die Daten wurden importiert. form_was_submitted_with_errors: "Das Formular wurde mit folgenden Fehlern übermittelt:" + block_content: + type: + content_text: Inhaltstext diff --git a/src/Resources/translations/messages.es.yml b/src/Resources/translations/messages.es.yml index cc481724e..9e832e76d 100755 --- a/src/Resources/translations/messages.es.yml +++ b/src/Resources/translations/messages.es.yml @@ -37,3 +37,6 @@ bitbag_sylius_cms_plugin: collections_subheader: Gestiona tus colecciones position: Posición title: Título + block_content: + type: + content_text: Texto diff --git a/src/Resources/translations/messages.fr.yml b/src/Resources/translations/messages.fr.yml index 904e9b1e9..a4de4a414 100755 --- a/src/Resources/translations/messages.fr.yml +++ b/src/Resources/translations/messages.fr.yml @@ -55,3 +55,6 @@ bitbag_sylius_cms_plugin: successfully_imported: Les données ont été importées. form_was_submitted_with_errors: "Le formulaire a les erreurs suivantes :" title: Titre + block_content: + type: + content_text: Texte diff --git a/src/Resources/translations/messages.hr.yml b/src/Resources/translations/messages.hr.yml index c19fddac3..9c26927f1 100755 --- a/src/Resources/translations/messages.hr.yml +++ b/src/Resources/translations/messages.hr.yml @@ -37,3 +37,6 @@ bitbag_sylius_cms_plugin: collections_subheader: Uredi kolekcije position: Pozicija (redosljed) title: Titula + block_content: + type: + content_text: Tekst diff --git a/src/Resources/translations/messages.lt.yml b/src/Resources/translations/messages.lt.yml index 055fa1245..629fccb48 100644 --- a/src/Resources/translations/messages.lt.yml +++ b/src/Resources/translations/messages.lt.yml @@ -54,4 +54,6 @@ bitbag_sylius_cms_plugin: csv_file: CSV failas successfully_imported: Duomenys sėkmingai importuoti. form_was_submitted_with_errors: "Forma pateikta su klaidomis:" - + block_content: + type: + content_text: Tekstas diff --git a/src/Resources/translations/messages.nl.yml b/src/Resources/translations/messages.nl.yml index 59c94b119..f7f8c2fad 100755 --- a/src/Resources/translations/messages.nl.yml +++ b/src/Resources/translations/messages.nl.yml @@ -36,3 +36,6 @@ bitbag_sylius_cms_plugin: collections_subheader: Beheer collecties position: Positie title: Titel + block_content: + type: + content_text: Tekst diff --git a/src/Resources/translations/messages.pl.yml b/src/Resources/translations/messages.pl.yml index f469d53bc..64a198f17 100755 --- a/src/Resources/translations/messages.pl.yml +++ b/src/Resources/translations/messages.pl.yml @@ -41,3 +41,6 @@ bitbag_sylius_cms_plugin: publish_at: Opublikuj page_will_be_publish_at: Strona zostanie opublikowana save_with_original_name: Zapisz z oryginalną nazwą + block_content: + type: + content_text: Tekst diff --git a/src/Resources/translations/messages.ru.yml b/src/Resources/translations/messages.ru.yml index f3b82f082..0564de330 100755 --- a/src/Resources/translations/messages.ru.yml +++ b/src/Resources/translations/messages.ru.yml @@ -54,3 +54,6 @@ bitbag_sylius_cms_plugin: csv_file: CSV файл successfully_imported: Данные успешно импортированы title: заглавие + block_content: + type: + content_text: Текст diff --git a/src/Resources/translations/messages.sk.yml b/src/Resources/translations/messages.sk.yml index 1185b5b14..d1ea95f5b 100644 --- a/src/Resources/translations/messages.sk.yml +++ b/src/Resources/translations/messages.sk.yml @@ -55,3 +55,6 @@ bitbag_sylius_cms_plugin: successfully_imported: Dáta boli naimportované form_was_submitted_with_errors: "Formulár obsahuje nasledovné chyby:" title: Titulok + block_content: + type: + content_text: Text diff --git a/src/Resources/translations/messages.uk.yml b/src/Resources/translations/messages.uk.yml index b2a528276..6ea8a63f5 100755 --- a/src/Resources/translations/messages.uk.yml +++ b/src/Resources/translations/messages.uk.yml @@ -54,3 +54,6 @@ bitbag_sylius_cms_plugin: csv_file: CSV файл successfully_imported: Дані успішно імпортовані title: заголовок + block_content: + type: + content_text: Текст From 9fc635bd14708987f762d4cb6a242465bd2f095a Mon Sep 17 00:00:00 2001 From: jkindly Date: Wed, 26 Jun 2024 08:16:41 +0200 Subject: [PATCH 23/27] OP-321: Update interface name --- src/Entity/Block.php | 2 +- src/Entity/BlockInterface.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Entity/Block.php b/src/Entity/Block.php index 0ed71c181..fec973f8c 100755 --- a/src/Entity/Block.php +++ b/src/Entity/Block.php @@ -15,7 +15,7 @@ class Block implements BlockInterface { use ToggleableTrait; - use CollectionableTrait; + use CollectibleTrait; use ChannelsAwareTrait; use BlockContentAwareTrait; use LocaleAwareTrait; diff --git a/src/Entity/BlockInterface.php b/src/Entity/BlockInterface.php index 7401581f0..63574180d 100755 --- a/src/Entity/BlockInterface.php +++ b/src/Entity/BlockInterface.php @@ -17,7 +17,7 @@ interface BlockInterface extends ResourceInterface, ToggleableInterface, - CollectionableInterface, + CollectibleInterface, ChannelsAwareInterface, BlockContentAwareInterface, LocaleAwareInterface, From 36de438329a71e021c932b5879215d3739f43c64 Mon Sep 17 00:00:00 2001 From: jkindly Date: Wed, 26 Jun 2024 08:42:53 +0200 Subject: [PATCH 24/27] OP-321: Behat tests update --- features/admin/adding_block.feature | 2 ++ features/admin/managing_blocks.feature | 2 ++ tests/Behat/Context/Ui/Admin/BlockContext.php | 8 ++++++++ tests/Behat/Page/Admin/Block/CreatePage.php | 7 +++++++ 4 files changed, 19 insertions(+) diff --git a/features/admin/adding_block.feature b/features/admin/adding_block.feature index 93aa26346..448b16e32 100644 --- a/features/admin/adding_block.feature +++ b/features/admin/adding_block.feature @@ -12,6 +12,7 @@ Feature: Adding blocks Scenario: Adding block When I go to the create block page And I fill the code with "store_description" + And I fill the name with "Store Description" And I add it Then I should be notified that the block has been created @@ -20,6 +21,7 @@ Feature: Adding blocks Given there are existing collections named "Blog" and "Homepage" When I go to the create block page And I fill the code with "intro" + And I fill the name with "Intro" And I add "Blog" and "Homepage" collections to it And I add it Then I should be notified that the block has been created diff --git a/features/admin/managing_blocks.feature b/features/admin/managing_blocks.feature index 6b4241137..b7429a7ae 100644 --- a/features/admin/managing_blocks.feature +++ b/features/admin/managing_blocks.feature @@ -20,6 +20,7 @@ Feature: Managing cms blocks Scenario: Updating block Given there is a block with "store_phone_number" code When I go to the update "store_phone_number" block page + And I fill the name with "Store phone number" if the name field is empty And I update it Then I should be notified that the block has been successfully updated @@ -27,6 +28,7 @@ Feature: Managing cms blocks Scenario: Disabling block Given there is an existing block with "bitbag_quote" code When I go to the update "bitbag_quote" block page + And I fill the name with "BitBag quote" if the name field is empty And I disable it And I update it Then I should be notified that the block has been successfully updated diff --git a/tests/Behat/Context/Ui/Admin/BlockContext.php b/tests/Behat/Context/Ui/Admin/BlockContext.php index c43b4830a..c6372c886 100755 --- a/tests/Behat/Context/Ui/Admin/BlockContext.php +++ b/tests/Behat/Context/Ui/Admin/BlockContext.php @@ -123,6 +123,14 @@ public function iFillTheNameWith(string $name): void $this->resolveCurrentPage()->fillName($name); } + /** + * @When I fill the name with :name if the name field is empty + */ + public function iFillTheNameIfItIsEmpty(string $name): void + { + $this->resolveCurrentPage()->fillNameIfItIsEmpty($name); + } + /** * @When I fill the link with :link */ diff --git a/tests/Behat/Page/Admin/Block/CreatePage.php b/tests/Behat/Page/Admin/Block/CreatePage.php index e3f9f8de4..08a0eaa9e 100755 --- a/tests/Behat/Page/Admin/Block/CreatePage.php +++ b/tests/Behat/Page/Admin/Block/CreatePage.php @@ -34,6 +34,13 @@ public function fillName(string $name): void $this->getDocument()->fillField('Name', $name); } + public function fillNameIfItIsEmpty(string $name): void + { + if (empty($this->getDocument()->findField('Name')->getValue())) { + $this->fillName($name); + } + } + public function fillLink(string $link): void { $this->getDocument()->fillField('Link', $link); From 51d132efc4e82cf875b4acfcfb7289e74fa22e59 Mon Sep 17 00:00:00 2001 From: jkindly Date: Wed, 26 Jun 2024 08:50:25 +0200 Subject: [PATCH 25/27] OP-321: Behat tests update --- tests/Behat/Page/Admin/Block/CreatePageInterface.php | 2 ++ tests/Behat/Page/Admin/Block/UpdatePage.php | 7 +++++++ tests/Behat/Page/Admin/Block/UpdatePageInterface.php | 2 ++ 3 files changed, 11 insertions(+) diff --git a/tests/Behat/Page/Admin/Block/CreatePageInterface.php b/tests/Behat/Page/Admin/Block/CreatePageInterface.php index 418b1f81d..0c44751e9 100755 --- a/tests/Behat/Page/Admin/Block/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Block/CreatePageInterface.php @@ -21,6 +21,8 @@ public function fillCode(string $code): void; public function fillName(string $name): void; + public function fillNameIfItIsEmpty(string $name): void; + public function fillLink(string $link): void; public function fillContent(string $content): void; diff --git a/tests/Behat/Page/Admin/Block/UpdatePage.php b/tests/Behat/Page/Admin/Block/UpdatePage.php index f0006b3d2..2aa6913b9 100755 --- a/tests/Behat/Page/Admin/Block/UpdatePage.php +++ b/tests/Behat/Page/Admin/Block/UpdatePage.php @@ -22,6 +22,13 @@ public function fillName(string $name): void $this->getDocument()->fillField('Name', $name); } + public function fillNameIfItIsEmpty(string $name): void + { + if (empty($this->getDocument()->findField('Name')->getValue())) { + $this->fillName($name); + } + } + public function fillLink(string $link): void { $this->getDocument()->fillField('Link', $link); diff --git a/tests/Behat/Page/Admin/Block/UpdatePageInterface.php b/tests/Behat/Page/Admin/Block/UpdatePageInterface.php index bedf81a96..72cc75c30 100755 --- a/tests/Behat/Page/Admin/Block/UpdatePageInterface.php +++ b/tests/Behat/Page/Admin/Block/UpdatePageInterface.php @@ -17,6 +17,8 @@ interface UpdatePageInterface extends BaseUpdatePageInterface, ChecksCodeImmutab { public function fillName(string $name): void; + public function fillNameIfItIsEmpty(string $name): void; + public function fillLink(string $link): void; public function fillContent(string $content): void; From 46d9f243177fc21046ae2e45e6b168a4830cea0f Mon Sep 17 00:00:00 2001 From: jkindly Date: Wed, 26 Jun 2024 08:57:41 +0200 Subject: [PATCH 26/27] OP-321: Behat tests update --- features/api/viewing_blocks.feature | 2 +- features/shop/displaying_homepage_block.feature | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/features/api/viewing_blocks.feature b/features/api/viewing_blocks.feature index c2453c011..cb9bc508c 100644 --- a/features/api/viewing_blocks.feature +++ b/features/api/viewing_blocks.feature @@ -7,7 +7,7 @@ Feature: Getting data from cms blocks Background: Given the store operates on a single channel in "United States" And there is a block in the store - And there is a block with "block-1" code and "Hi there!" content + And there is a block with "block-1" code @api Scenario: Browsing blocks diff --git a/features/shop/displaying_homepage_block.feature b/features/shop/displaying_homepage_block.feature index b269cd4f5..36b20d9c2 100644 --- a/features/shop/displaying_homepage_block.feature +++ b/features/shop/displaying_homepage_block.feature @@ -9,6 +9,6 @@ Feature: Displaying blocks @ui Scenario: Displaying homepage blocks - Given there is a block with "homepage_intro" code and "Hello world!" content + Given there is a block with "homepage_intro" code When I go to the homepage And I want to see a text block with "Hello world!" content From 721d9e7b68805220a35f357e50c2359870c29334 Mon Sep 17 00:00:00 2001 From: jkindly Date: Wed, 26 Jun 2024 09:06:59 +0200 Subject: [PATCH 27/27] OP-321: Behat tests update --- features/shop/displaying_homepage_block.feature | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 features/shop/displaying_homepage_block.feature diff --git a/features/shop/displaying_homepage_block.feature b/features/shop/displaying_homepage_block.feature deleted file mode 100644 index 36b20d9c2..000000000 --- a/features/shop/displaying_homepage_block.feature +++ /dev/null @@ -1,14 +0,0 @@ -@shop_blocks -Feature: Displaying blocks - In order to buy more items in the store - As a Customer - I want to display content blocks on the homepage - - Background: - Given the store operates on a single channel in "United States" - - @ui - Scenario: Displaying homepage blocks - Given there is a block with "homepage_intro" code - When I go to the homepage - And I want to see a text block with "Hello world!" content