Skip to content

Commit

Permalink
OP-461: Template form validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jkindly committed Jul 31, 2024
1 parent c2d883f commit 1069aed
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Form/Type/TemplateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

namespace BitBag\SyliusCmsPlugin\Form\Type;

use Symfony\Component\Form\AbstractType;
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;

final class TemplateType extends AbstractType
final class TemplateType extends AbstractResourceType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ parameters:
bitbag_sylius_cms_plugin.form.type.collection.validation_groups: "%bitbag_validation_group%"
bitbag_sylius_cms_plugin.form.type.translation.media.validation_groups: "%bitbag_validation_group%"
bitbag_sylius_cms_plugin.form.type.media.validation_groups: "%bitbag_validation_group%"
bitbag_sylius_cms_plugin.form.type.template.validation_groups: "%bitbag_validation_group%"
bitbag_sylius_cms_plugin.uploader.filesystem: bitbag_sylius_cms_plugin_media

jms_serializer:
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/config/services/form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
</service>

<service id="bitbag_sylius_cms_plugin.form.type.template" class="BitBag\SyliusCmsPlugin\Form\Type\TemplateType">
<argument>%bitbag_sylius_cms_plugin.model.template.class%</argument>
<argument>%bitbag_sylius_cms_plugin.form.type.template.validation_groups%</argument>
<tag name="form.type" />
</service>

Expand Down
35 changes: 35 additions & 0 deletions src/Resources/config/validation/Template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping
http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">

<class name="BitBag\SyliusCmsPlugin\Entity\Template">
<constraint name="Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity">
<option name="fields">
<value>name</value>
</option>
<option name="groups">
<value>bitbag</value>
</option>
<option name="message">bitbag_sylius_cms_plugin.template.name.unique</option>
</constraint>

<property name="name">
<constraint name="NotBlank">
<option name="message">bitbag_sylius_cms_plugin.template.name.not_blank</option>
<option name="groups">
<value>bitbag</value>
</option>
</constraint>
<constraint name="Length">
<option name="min">2</option>
<option name="max">250</option>
<option name="minMessage">bitbag_sylius_cms_plugin.template.name.min_length</option>
<option name="maxMessage">bitbag_sylius_cms_plugin.template.name.max_length</option>
<option name="groups">
<value>bitbag</value>
</option>
</constraint>
</property>
</class>
</constraint-mapping>

0 comments on commit 1069aed

Please sign in to comment.