From cee65775ff48de097c485b107b18412ef262831e Mon Sep 17 00:00:00 2001 From: Patryk Date: Sat, 11 Nov 2017 18:55:48 +0100 Subject: [PATCH 1/3] [Block] Fix validation groups --- src/Form/Type/BlockType.php | 13 +++++++++++++ src/Resources/config/services/form.yml | 18 +++++++++--------- src/Resources/config/validation/BlockImage.yml | 2 +- src/Resources/translations/validators.en.yml | 2 +- 4 files changed, 24 insertions(+), 11 deletions(-) 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..09af16b7a 100644 --- a/src/Resources/config/services/form.yml +++ b/src/Resources/config/services/form.yml @@ -11,7 +11,7 @@ services: class: BitBag\CmsPlugin\Form\Type\Translation\TextBlockTranslationType arguments: - "%bitbag.model.block_translation.class%" - - ['bitbag', 'bitbag_content'] + - [] tags: - { name: form.type } @@ -19,7 +19,7 @@ services: class: BitBag\CmsPlugin\Form\Type\Translation\HtmlBlockTranslationType arguments: - "%bitbag.model.block_translation.class%" - - ['bitbag', 'bitbag_content'] + - [] tags: - { name: form.type } @@ -27,7 +27,7 @@ services: class: BitBag\CmsPlugin\Form\Type\Translation\ImageBlockTranslationType arguments: - "%bitbag.model.block_translation.class%" - - ['bitbag', 'bitbag_image'] + - [] tags: - { name: form.type } @@ -72,12 +72,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 e7915da7d..c5f8790eb 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. From 224802d74d953cdbaff65dc88ae7958c00761a87 Mon Sep 17 00:00:00 2001 From: Patryk Date: Sat, 11 Nov 2017 19:12:57 +0100 Subject: [PATCH 2/3] Cleanup --- src/Resources/config/services/form.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Resources/config/services/form.yml b/src/Resources/config/services/form.yml index 09af16b7a..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%" - - [] tags: - { name: form.type } @@ -19,7 +18,6 @@ services: class: BitBag\CmsPlugin\Form\Type\Translation\HtmlBlockTranslationType arguments: - "%bitbag.model.block_translation.class%" - - [] tags: - { name: form.type } @@ -27,7 +25,6 @@ services: class: BitBag\CmsPlugin\Form\Type\Translation\ImageBlockTranslationType arguments: - "%bitbag.model.block_translation.class%" - - [] tags: - { name: form.type } From d36166754739e11fd52327a4eea04f8965d1c1bf Mon Sep 17 00:00:00 2001 From: Patryk Date: Sat, 11 Nov 2017 19:24:23 +0100 Subject: [PATCH 3/3] [Behat] @todo change to @ui --- features/admin/adding_block.feature | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/features/admin/adding_block.feature b/features/admin/adding_block.feature index 7708e44f6..c62f69914 100644 --- a/features/admin/adding_block.feature +++ b/features/admin/adding_block.feature @@ -44,19 +44,19 @@ Feature: Adding blocks And I add it Then I should be notified that the block has been created - @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