diff --git a/features/admin/adding_block.feature b/features/admin/adding_block.feature index e0e94ab27..b4b21522f 100644 --- a/features/admin/adding_block.feature +++ b/features/admin/adding_block.feature @@ -52,19 +52,19 @@ Feature: Adding blocks And I try to add it Then I should be notified that there is already an existing block with provided code - @todo + @ui Scenario: Trying to add text block with blank data When I go to the create "text" block page And I try to add it Then I should be notified that "Code, Content" cannot be blank - @todo + @ui Scenario: Trying to add html block with blank data When I go to the create "html" block page And I try to add it Then I should be notified that "Code, Content" cannot be blank - @todo + @ui Scenario: Trying to add image block with blank data When I go to the create "image" block page And I try to add it diff --git a/src/Form/Type/BlockType.php b/src/Form/Type/BlockType.php index a8a3c765a..1b4056c68 100644 --- a/src/Form/Type/BlockType.php +++ b/src/Form/Type/BlockType.php @@ -22,6 +22,7 @@ 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; /** * @author Patryk Drapik @@ -68,6 +69,10 @@ private function resolveBlockType(BlockInterface $block, FormBuilderInterface $b $builder->add('translations', ResourceTranslationsType::class, [ 'label' => 'bitbag.ui.contents', 'entry_type' => TextBlockTranslationType::class, + 'validation_groups' => ['bitbag_content'], + 'constraints' => [ + new Valid(), + ], ]); return; @@ -77,6 +82,10 @@ private function resolveBlockType(BlockInterface $block, FormBuilderInterface $b $builder->add('translations', ResourceTranslationsType::class, [ 'label' => 'bitbag.ui.contents', 'entry_type' => HtmlBlockTranslationType::class, + 'validation_groups' => ['bitbag_content'], + 'constraints' => [ + new Valid(), + ], ]); return; @@ -86,6 +95,10 @@ private function resolveBlockType(BlockInterface $block, FormBuilderInterface $b $builder->add('translations', ResourceTranslationsType::class, [ 'label' => 'bitbag.ui.images', 'entry_type' => ImageBlockTranslationType::class, + 'validation_groups' => null === $block->getId() ? ['bitbag_image'] : [], + 'constraints' => [ + new Valid(), + ], ]); return; diff --git a/src/Resources/config/services/form.yml b/src/Resources/config/services/form.yml index 21e0a333e..f6ecb437b 100644 --- a/src/Resources/config/services/form.yml +++ b/src/Resources/config/services/form.yml @@ -11,7 +11,6 @@ services: class: BitBag\CmsPlugin\Form\Type\Translation\TextBlockTranslationType arguments: - "%bitbag.model.block_translation.class%" - - ['bitbag', 'bitbag_content'] tags: - { name: form.type } @@ -19,7 +18,6 @@ services: class: BitBag\CmsPlugin\Form\Type\Translation\HtmlBlockTranslationType arguments: - "%bitbag.model.block_translation.class%" - - ['bitbag', 'bitbag_content'] tags: - { name: form.type } @@ -27,7 +25,6 @@ services: class: BitBag\CmsPlugin\Form\Type\Translation\ImageBlockTranslationType arguments: - "%bitbag.model.block_translation.class%" - - ['bitbag', 'bitbag_image'] tags: - { name: form.type } @@ -72,12 +69,12 @@ services: - { name: form.type } bitbag.form.type.section: - class: BitBag\CmsPlugin\Form\Type\SectionType - arguments: - - "%bitbag.model.section.class%" - - ['bitbag'] - tags: - - { name: form.type } + class: BitBag\CmsPlugin\Form\Type\SectionType + arguments: + - "%bitbag.model.section.class%" + - ['bitbag'] + tags: + - { name: form.type } bitbag.form.type.translation.section: class: BitBag\CmsPlugin\Form\Type\Translation\SectionTranslationType diff --git a/src/Resources/config/validation/BlockImage.yml b/src/Resources/config/validation/BlockImage.yml index 0b04a068a..b965d38db 100644 --- a/src/Resources/config/validation/BlockImage.yml +++ b/src/Resources/config/validation/BlockImage.yml @@ -2,5 +2,5 @@ BitBag\CmsPlugin\Entity\BlockImage: properties: file: - NotBlank: - message: 'bitbag.cms.block.image.not_blank' + message: 'bitbag.block.image.not_blank' groups: ['bitbag_image'] \ No newline at end of file diff --git a/src/Resources/translations/validators.en.yml b/src/Resources/translations/validators.en.yml index f8b097f65..fdacc95ac 100755 --- a/src/Resources/translations/validators.en.yml +++ b/src/Resources/translations/validators.en.yml @@ -2,7 +2,7 @@ bitbag: block: image: mime_types: Only PNG and JPEG files are allowed. - not_blank: Upload an image. + not_blank: Image cannot be blank. code: unique: There is an existing block with this code. not_blank: Code cannot be blank.