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 @@ +<?php + +/* + * This file was created by developers working at BitBag + * Do you need more information about us and what we do? Visit our https://bitbag.io website! + * 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; + +final class BlockContent implements BlockContentInterface +{ + protected ?int $id; + + protected ?string $type; + + protected array $configuration = []; + + protected ?BlockInterface $block; + + public function getId(): ?int + { + return $this->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 @@ +<?php + +/* + * This file was created by developers working at BitBag + * Do you need more information about us and what we do? Visit our https://bitbag.io website! + * 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; + +use Doctrine\Common\Collections\Collection; + +interface BlockContentAwareInterface +{ + public function initializeContentsCollection(): void; + + public function getContents(): Collection; + + public function hasContent(BlockContentInterface $contentItem): bool; + + public function addContent(BlockContentInterface $contentItem): void; + + public function removeContent(BlockContentInterface $contentItem): void; +} diff --git a/src/Entity/BlockContentAwareTrait.php b/src/Entity/BlockContentAwareTrait.php new file mode 100644 index 000000000..c7044f819 --- /dev/null +++ b/src/Entity/BlockContentAwareTrait.php @@ -0,0 +1,48 @@ +<?php + +/* + * This file was created by developers working at BitBag + * Do you need more information about us and what we do? Visit our https://bitbag.io website! + * 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; + +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; + +trait BlockContentAwareTrait +{ + protected Collection $contents; + + public function initializeContentsCollection(): void + { + $this->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 @@ +<?php + +/* + * This file was created by developers working at BitBag + * Do you need more information about us and what we do? Visit our https://bitbag.io website! + * 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; + +use Sylius\Component\Resource\Model\ResourceInterface; + +interface BlockContentInterface extends ResourceInterface +{ + public function getId(): ?int; + + public function getType(): ?string; + + public function setType(?string $type): void; + + public function getConfiguration(): array; + + public function setConfiguration(array $configuration): void; + + public function getBlock(): ?BlockInterface; + + public function setBlock(?BlockInterface $block): void; +} diff --git a/src/Entity/BlockInterface.php b/src/Entity/BlockInterface.php index e8a9d313e..8759ad91a 100755 --- a/src/Entity/BlockInterface.php +++ b/src/Entity/BlockInterface.php @@ -23,7 +23,8 @@ interface BlockInterface extends TaxonAwareInterface, CollectionableInterface, ChannelsAwareInterface, - ContentableInterface + ContentableInterface, + BlockContentAwareInterface { public function getCode(): ?string; diff --git a/src/Entity/BlockTranslation.php b/src/Entity/BlockTranslation.php index 146a5b188..68d877df8 100755 --- a/src/Entity/BlockTranslation.php +++ b/src/Entity/BlockTranslation.php @@ -17,25 +17,9 @@ class BlockTranslation extends AbstractTranslation implements BlockTranslationIn /** @var int */ protected $id; - /** @var string|null */ - protected $name; - /** @var string|null */ protected $content; - /** @var string|null */ - protected $link; - - public function getName(): ?string - { - return $this->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 @@ +<?php + +/* + * This file was created by developers working at BitBag + * Do you need more information about us and what we do? Visit our https://bitbag.io website! + * 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\Form\Type\BlockContent; + +use BitBag\SyliusCmsPlugin\Form\Type\WysiwygType; +use Symfony\Component\Form\AbstractType; +use Symfony\Component\OptionsResolver\OptionsResolver; + +final class BlockContentTextConfigurationType extends AbstractType +{ + public const TYPE = 'content_text'; + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->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 @@ +<?php + +/* + * This file was created by developers working at BitBag + * Do you need more information about us and what we do? Visit our https://bitbag.io website! + * 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\Form\Type; + +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; +use Symfony\Component\Form\FormEvents; + +final class BlockContentType extends AbstractResourceType +{ + private array $actionTypes = []; + + private array $actionConfigurationTypes; + + public function __construct( + string $dataClass, + array $validationGroups, + iterable $actionConfigurationTypes, + ) { + parent::__construct($dataClass, $validationGroups); + + foreach ($actionConfigurationTypes as $type => $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 @@ +<?php + +declare(strict_types=1); + +namespace BitBag\SyliusCmsPlugin\Migrations; + +use Doctrine\DBAL\Schema\Schema; +use Doctrine\Migrations\AbstractMigration; + +/** + * Auto-generated Migration: Please modify to your needs! + */ +final class Version20240621093611 extends AbstractMigration +{ + public function getDescription(): string + { + return ''; + } + + public function up(Schema $schema): void + { + // this up() migration is auto-generated, please modify it to your needs + $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_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 @@ +<?php + +/* + * This file was created by developers working at BitBag + * Do you need more information about us and what we do? Visit our https://bitbag.io website! + * 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\Repository; + +use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository; + +class BlockContentRepository extends EntityRepository +{ +} diff --git a/src/Resources/config/config.yml b/src/Resources/config/config.yml index 311f64932..cd3f466d4 100755 --- a/src/Resources/config/config.yml +++ b/src/Resources/config/config.yml @@ -8,6 +8,7 @@ parameters: sylius.sitemap.path: "%kernel.project_dir%/var/sitemap" 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%" diff --git a/src/Resources/config/doctrine/Block.orm.xml b/src/Resources/config/doctrine/Block.orm.xml index c176b5c25..b62cc1115 100644 --- a/src/Resources/config/doctrine/Block.orm.xml +++ b/src/Resources/config/doctrine/Block.orm.xml @@ -12,6 +12,8 @@ <field name="code" column="code" type="string" length="64" unique="true"/> + <field name="name" column="name" type="string" length="250" nullable="true"/> + <field name="enabled" column="enabled" type="boolean"/> <many-to-many field="collections" target-entity="BitBag\SyliusCmsPlugin\Entity\CollectionInterface"> @@ -58,5 +60,11 @@ </join-table> </many-to-many> + <one-to-many field="contents" target-entity="BitBag\SyliusCmsPlugin\Entity\BlockContent" mapped-by="block" orphan-removal="true"> + <cascade> + <cascade-all/> + </cascade> + </one-to-many> + </mapped-superclass> </doctrine-mapping> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<doctrine-mapping xmlns="https://doctrine-project.org/schemas/orm/doctrine-mapping" + xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="https://doctrine-project.org/schemas/orm/doctrine-mapping + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> + + <mapped-superclass name="BitBag\SyliusCmsPlugin\Entity\BlockContent" table="bitbag_cms_block_content"> + <id name="id" type="integer"> + <generator strategy="AUTO" /> + </id> + + <field name="type" type="string" /> + + <field name="configuration" type="json"> + <options> + <option name="jsonb">true</option> + </options> + </field> + + <many-to-one field="block" target-entity="BitBag\SyliusCmsPlugin\Entity\Block" inversed-by="contents"> + <join-column name="block_id" referenced-column-name="id" nullable="true" /> + </many-to-one> + </mapped-superclass> + +</doctrine-mapping> 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 @@ <generator strategy="AUTO"/> </id> - <field name="name" column="name" type="string" nullable="true"/> - <field name="content" column="content" type="text" nullable="true"/> - - <field name="link" column="link" type="text" nullable="true"/> </mapped-superclass> -</doctrine-mapping> \ No newline at end of file +</doctrine-mapping> 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 @@ <attribute name="translations"> <group>shop:cms:read</group> </attribute> + <attribute name="contents"> + <group>shop:cms:read</group> + </attribute> </class> </serializer> 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" > <class name="BitBag\SyliusCmsPlugin\Entity\BlockTranslation"> - <attribute name="name"> - <group>shop:cms:read</group> - </attribute> <attribute name="content"> <group>shop:cms:read</group> </attribute> - <attribute name="link"> - <group>shop:cms:read</group> - </attribute> </class> </serializer> 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 @@ <?xml version="1.0" encoding="UTF-8"?> <container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> + <parameters> + <parameter key="bitbag_sylius_cms_plugin.block_content.action.content_text" type="constant">BitBag\SyliusCmsPlugin\Form\Type\BlockContent\BlockContentTextConfigurationType::TYPE</parameter> + </parameters> + <services> <defaults public="true" /> @@ -10,6 +14,13 @@ <tag name="form.type" /> </service> + <service id="bitbag_sylius_cms_plugin.form.type.block_content" class="BitBag\SyliusCmsPlugin\Form\Type\BlockContentType"> + <argument>BitBag\SyliusCmsPlugin\Entity\BlockContent</argument> + <argument>%bitbag_sylius_cms_plugin.form.type.block_content.validation_groups%</argument> + <argument type="tagged_iterator" tag="bitbag_sylius_cms_plugin.block_content.action_configuration_type" index-by="key" /> + <tag name="form.type" /> + </service> + <service id="bitbag_sylius_cms_plugin.form.type.translation.block" class="BitBag\SyliusCmsPlugin\Form\Type\Translation\BlockTranslationType"> <argument>%bitbag_sylius_cms_plugin.model.block_translation.class%</argument> <argument>%bitbag_sylius_cms_plugin.form.type.translation.block.validation_groups%</argument> @@ -79,6 +90,12 @@ <argument type="service" id="router.default" /> <tag name="form.type" /> </service> + + <service id="BitBag\SyliusCmsPlugin\Form\Type\BlockContent\BlockContentTextConfigurationType"> + <tag name="bitbag_sylius_cms_plugin.block_content.action_configuration_type" key="%bitbag_sylius_cms_plugin.block_content.action.content_text%" /> + <tag name="form.type" /> + </service> + </services> </container> 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"> <class name="BitBag\SyliusCmsPlugin\Entity\BlockTranslation"> - <property name="name"> - <constraint name="Length"> - <option name="min">2</option> - <option name="max">250</option> - <option name="minMessage">bitbag_sylius_cms_plugin.block.name.min_length</option> - <option name="maxMessage">bitbag_sylius_cms_plugin.block.name.max_length</option> - <option name="groups"> - <value>bitbag</value> - </option> - </constraint> - </property> - - <property name="link"> - <constraint name="Length"> - <option name="min">2</option> - <option name="max">250</option> - <option name="minMessage">bitbag_sylius_cms_plugin.block.link.min_length</option> - <option name="maxMessage">bitbag_sylius_cms_plugin.block.link.max_length</option> - <option name="groups"> - <value>bitbag</value> - </option> - </constraint> - </property> - <property name="content"> <constraint name="Length"> <option name="min">2</option> 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' %} - -<div class="ui two column stackable grid" data-bb-target="cms-handle-preview"> +<div class="ui two column stackable grid"> <div class="column"> <div class="ui segment"> {{ 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) }} + </div> + </div> +</div> - <a - href="#" - class="ui labeled button icon primary bitbag-cms-resource-preview" - data-url="{{ path('bitbag_sylius_cms_plugin_admin_block_preview') }}" - data-bb-cms-preview-btn - > - <i class="eye icon"></i> - {{ 'bitbag_sylius_cms_plugin.ui.preview'|trans }} - </a> +<div class="ui one column stackable grid"> + <div class="column"> + <div class="ui segment"> + <h4 class="ui dividing header">{{ 'sylius.ui.configuration'|trans }}</h4> + <div class="ui two column stackable grid"> + <div class="column" id="actions"> + {{ form_row(form.contents) }} + </div> + </div> </div> </div> </div>