From c1eb277a6a8e76ab7d05e14f84c38c8b6b97bf06 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Thu, 19 Oct 2023 20:51:23 +0200 Subject: [PATCH] add 'Length' constraint in forms --- CHANGELOG.md | 1 + .../DependencyInjection/Configuration.php | 187 +++++++++--------- src/core/Form/Site/MenuType.php | 3 + .../Site/NavigationAdditionalDomainType.php | 2 + src/core/Form/Site/NavigationType.php | 5 +- src/core/Form/Site/NodeType.php | 7 + src/core/Form/Site/Page/PageType.php | 6 + 7 files changed, 117 insertions(+), 94 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c35ae8c..0a78a88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Added * allow to define templates show before and after a murph collection item * add global batch actions +* add constraint `Length` in forms ### Fixed * fix regression on crud sorting diff --git a/src/core/DependencyInjection/Configuration.php b/src/core/DependencyInjection/Configuration.php index 86ef226..14a721b 100644 --- a/src/core/DependencyInjection/Configuration.php +++ b/src/core/DependencyInjection/Configuration.php @@ -46,99 +46,100 @@ class Configuration implements ConfigurationInterface $treeBuilder->getRootNode() ->children() - ->arrayNode('site') - ->children() - ->scalarNode('name') - ->defaultValue('Murph') - ->isRequired() - ->end() - ->scalarNode('logo') - ->defaultValue('build/images/core/logo.svg') - ->isRequired() - ->end() - ->arrayNode('controllers') - ->prototype('array') - ->children() - ->scalarNode('name') - ->cannotBeEmpty() - ->end() - ->scalarNode('action') - ->cannotBeEmpty() - ->end() - ->end() - ->end() - ->end() - ->arrayNode('security') - ->children() - ->arrayNode('roles') - ->prototype('array') - ->children() - ->scalarNode('name') - ->cannotBeEmpty() - ->end() - ->scalarNode('role') - ->cannotBeEmpty() - ->end() - ->end() - ->end() - ->end() - ->end() - ->end() - ->arrayNode('pages') - ->prototype('array') - ->children() - ->scalarNode('name') - ->isRequired() - ->cannotBeEmpty() - ->end() - ->arrayNode('templates') - ->prototype('array') - ->children() - ->scalarNode('name') - ->cannotBeEmpty() - ->end() - ->scalarNode('file') - ->cannotBeEmpty() - ->end() - ->end() - ->end() - ->end() - ->end() - ->end() - ->end() - ->end() - ->end() - ->arrayNode('editor_js') - ->children() - ->arrayNode('blocks') - ->scalarPrototype() - ->end() - ->end() - ->end() - ->end() - ->arrayNode('file_manager') - ->children() - ->arrayNode('mimes') - ->scalarPrototype() - ->end() - ->defaultValue($defaultMimetypes) - ->end() - ->scalarNode('path') - ->defaultValue('%kernel.project_dir%/public/uploads') - ->cannotBeEmpty() - ->end() - ->scalarNode('path_uri') - ->defaultValue('/uploads') - ->cannotBeEmpty() - ->end() - ->arrayNode('path_locked') - ->scalarPrototype() - ->end() - ->defaultValue($defaultLocked) - ->end() - ->end() - ->end() - ->end(); + ->arrayNode('site') + ->children() + ->scalarNode('name') + ->defaultValue('Murph') + ->isRequired() + ->end() + ->scalarNode('logo') + ->defaultValue('build/images/core/logo.svg') + ->isRequired() + ->end() + ->arrayNode('controllers') + ->prototype('array') + ->children() + ->scalarNode('name') + ->cannotBeEmpty() + ->end() + ->scalarNode('action') + ->cannotBeEmpty() + ->end() + ->end() + ->end() + ->end() + ->arrayNode('security') + ->children() + ->arrayNode('roles') + ->prototype('array') + ->children() + ->scalarNode('name') + ->cannotBeEmpty() + ->end() + ->scalarNode('role') + ->cannotBeEmpty() + ->end() + ->end() + ->end() + ->end() + ->end() + ->end() + ->arrayNode('pages') + ->prototype('array') + ->children() + ->scalarNode('name') + ->isRequired() + ->cannotBeEmpty() + ->end() + ->arrayNode('templates') + ->prototype('array') + ->children() + ->scalarNode('name') + ->cannotBeEmpty() + ->end() + ->scalarNode('file') + ->cannotBeEmpty() + ->end() + ->end() + ->end() + ->end() + ->end() + ->end() + ->end() + ->end() + ->end() + ->arrayNode('editor_js') + ->children() + ->arrayNode('blocks') + ->scalarPrototype() + ->end() + ->end() + ->end() + ->end() + ->arrayNode('file_manager') + ->children() + ->arrayNode('mimes') + ->scalarPrototype() + ->end() + ->defaultValue($defaultMimetypes) + ->end() + ->scalarNode('path') + ->defaultValue('%kernel.project_dir%/public/uploads') + ->cannotBeEmpty() + ->end() + ->scalarNode('path_uri') + ->defaultValue('/uploads') + ->cannotBeEmpty() + ->end() + ->arrayNode('path_locked') + ->scalarPrototype() + ->end() + ->defaultValue($defaultLocked) + ->end() + ->end() + ->end() + ->end() + ; return $treeBuilder; } diff --git a/src/core/Form/Site/MenuType.php b/src/core/Form/Site/MenuType.php index 3efefdd..6ff2275 100644 --- a/src/core/Form/Site/MenuType.php +++ b/src/core/Form/Site/MenuType.php @@ -7,6 +7,7 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; +use Symfony\Component\Validator\Constraints\Length; use Symfony\Component\Validator\Constraints\NotBlank; class MenuType extends AbstractType @@ -23,6 +24,7 @@ class MenuType extends AbstractType ], 'constraints' => [ new NotBlank(), + new Length(max: 255), ], ] ); @@ -37,6 +39,7 @@ class MenuType extends AbstractType ], 'constraints' => [ new NotBlank(), + new Length(max: 255), ], ] ); diff --git a/src/core/Form/Site/NavigationAdditionalDomainType.php b/src/core/Form/Site/NavigationAdditionalDomainType.php index cc4ecf4..ab91563 100644 --- a/src/core/Form/Site/NavigationAdditionalDomainType.php +++ b/src/core/Form/Site/NavigationAdditionalDomainType.php @@ -7,6 +7,7 @@ use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; +use Symfony\Component\Validator\Constraints\Length; use Symfony\Component\Validator\Constraints\NotBlank; class NavigationAdditionalDomainType extends AbstractType @@ -24,6 +25,7 @@ class NavigationAdditionalDomainType extends AbstractType ], 'constraints' => [ new NotBlank(), + new Length(max: 255), ], ] ); diff --git a/src/core/Form/Site/NavigationType.php b/src/core/Form/Site/NavigationType.php index 01cc54e..a6c3278 100644 --- a/src/core/Form/Site/NavigationType.php +++ b/src/core/Form/Site/NavigationType.php @@ -27,6 +27,7 @@ class NavigationType extends AbstractType ], 'constraints' => [ new NotBlank(), + new Length(max: 255), ], ] ); @@ -41,6 +42,7 @@ class NavigationType extends AbstractType ], 'constraints' => [ new NotBlank(), + new Length(max: 255), ], ] ); @@ -69,6 +71,7 @@ class NavigationType extends AbstractType ], 'constraints' => [ new NotBlank(), + new Length(max: 255), ], ] ); @@ -109,7 +112,7 @@ class NavigationType extends AbstractType ], 'constraints' => [ new NotBlank(), - new Length(['min' => 2, 'max' => 10]), + new Length(min: 2, max: 10), ], ] ); diff --git a/src/core/Form/Site/NodeType.php b/src/core/Form/Site/NodeType.php index 3f2a454..a60552f 100644 --- a/src/core/Form/Site/NodeType.php +++ b/src/core/Form/Site/NodeType.php @@ -13,6 +13,7 @@ use Symfony\Component\Form\Extension\Core\Type\CollectionType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; +use Symfony\Component\Validator\Constraints\Length; use Symfony\Component\Validator\Constraints\NotBlank; class NodeType extends AbstractType @@ -29,6 +30,7 @@ class NodeType extends AbstractType ], 'constraints' => [ new NotBlank(), + new Length(max: 255), ], ] ); @@ -43,6 +45,7 @@ class NodeType extends AbstractType 'attr' => [ ], 'constraints' => [ + new Length(max: 255), ], ] ); @@ -82,6 +85,7 @@ class NodeType extends AbstractType 'attr' => [ ], 'constraints' => [ + new Length(max: 255), ], ] ); @@ -116,6 +120,9 @@ class NodeType extends AbstractType return $choices; }), + 'constraints' => [ + new Length(max: 255), + ], ] ); diff --git a/src/core/Form/Site/Page/PageType.php b/src/core/Form/Site/Page/PageType.php index 352c740..40cb428 100644 --- a/src/core/Form/Site/Page/PageType.php +++ b/src/core/Form/Site/Page/PageType.php @@ -10,6 +10,7 @@ use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Validator\Constraints\Image; +use Symfony\Component\Validator\Constraints\Length; use Symfony\Component\Validator\Constraints\NotBlank; class PageType extends AbstractType @@ -26,6 +27,7 @@ class PageType extends AbstractType ], 'constraints' => [ new NotBlank(), + new Length(max: 255), ], ] ); @@ -39,6 +41,7 @@ class PageType extends AbstractType 'attr' => [ ], 'constraints' => [ + new Length(max: 255), ], ] ); @@ -52,6 +55,7 @@ class PageType extends AbstractType 'attr' => [ ], 'constraints' => [ + new Length(max: 255), ], ] ); @@ -65,6 +69,7 @@ class PageType extends AbstractType 'attr' => [ ], 'constraints' => [ + new Length(max: 255), ], ] ); @@ -78,6 +83,7 @@ class PageType extends AbstractType 'attr' => [ ], 'constraints' => [ + new Length(max: 255), ], ] );