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) }} -
-