diff --git a/src/Bundle/ChillBudgetBundle/Entity/ChargeKind.php b/src/Bundle/ChillBudgetBundle/Entity/ChargeKind.php index d1393eafb..b6ebcf347 100644 --- a/src/Bundle/ChillBudgetBundle/Entity/ChargeKind.php +++ b/src/Bundle/ChillBudgetBundle/Entity/ChargeKind.php @@ -12,12 +12,17 @@ declare(strict_types=1); namespace Chill\BudgetBundle\Entity; use Doctrine\ORM\Mapping as ORM; +use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; +use Symfony\Component\Validator\Constraints as Assert; /** * Type of charge. * - * @ORM\Table(name="chill_budget.charge_type") + * @ORM\Table(name="chill_budget.charge_type", + * uniqueConstraints={@ORM\UniqueConstraint(name="charge_kind_unique_type_idx", fields={"kind"})} + * ) * @ORM\Entity + * @UniqueEntity(fields={"kind"}) */ class ChargeKind { @@ -35,6 +40,8 @@ class ChargeKind /** * @ORM\Column(type="string", length=255, options={"default": ""}, nullable=false) + * @Assert\Regex(pattern="/^[a-z0-9\-_]{1,}$/", message="budget.admin.form.kind.only_alphanumeric") + * @Assert\Length(min=3) */ private string $kind = ''; diff --git a/src/Bundle/ChillBudgetBundle/Entity/ResourceKind.php b/src/Bundle/ChillBudgetBundle/Entity/ResourceKind.php index 5d88af298..4b90be5e1 100644 --- a/src/Bundle/ChillBudgetBundle/Entity/ResourceKind.php +++ b/src/Bundle/ChillBudgetBundle/Entity/ResourceKind.php @@ -12,12 +12,17 @@ declare(strict_types=1); namespace Chill\BudgetBundle\Entity; use Doctrine\ORM\Mapping as ORM; +use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; +use Symfony\Component\Validator\Constraints as Assert; /** * Type of resource. * - * @ORM\Table(name="chill_budget.resource_type") + * @ORM\Table(name="chill_budget.resource_type", uniqueConstraints={ + * @ORM\UniqueConstraint(name="resource_kind_unique_type_idx", fields={"kind"}) + * }) * @ORM\Entity + * @UniqueEntity(fields={"kind"}) */ class ResourceKind { @@ -35,6 +40,8 @@ class ResourceKind /** * @ORM\Column(type="string", length=255, nullable=false, options={"default": ""}) + * @Assert\Regex(pattern="/^[a-z0-9\-_]{1,}$/", message="budget.admin.form.kind.only_alphanumeric") + * @Assert\Length(min=3) */ private string $kind = ''; diff --git a/src/Bundle/ChillBudgetBundle/Form/Admin/ChargeKindType.php b/src/Bundle/ChillBudgetBundle/Form/Admin/ChargeKindType.php index 661199aec..59adf49af 100644 --- a/src/Bundle/ChillBudgetBundle/Form/Admin/ChargeKindType.php +++ b/src/Bundle/ChillBudgetBundle/Form/Admin/ChargeKindType.php @@ -16,6 +16,7 @@ use Chill\MainBundle\Form\Type\TranslatableStringFormType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\NumberType; +use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -25,7 +26,11 @@ class ChargeKindType extends AbstractType { $builder ->add('name', TranslatableStringFormType::class, [ - 'label' => 'Nom', + 'label' => 'Title', + ]) + ->add('kind', TextType::class, [ + 'label' => 'budget.admin.form.Charge_kind_key', + 'help' => 'budget.admin.form.This kind must contains only alphabeticals characters, and dashes. This string is in use during document generation. Changes may have side effect on document' ]) ->add('ordering', NumberType::class) ->add('isActive', CheckboxType::class, [ diff --git a/src/Bundle/ChillBudgetBundle/Form/Admin/ResourceKindType.php b/src/Bundle/ChillBudgetBundle/Form/Admin/ResourceKindType.php index 7b2622c5d..0605b8731 100644 --- a/src/Bundle/ChillBudgetBundle/Form/Admin/ResourceKindType.php +++ b/src/Bundle/ChillBudgetBundle/Form/Admin/ResourceKindType.php @@ -16,6 +16,7 @@ use Chill\MainBundle\Form\Type\TranslatableStringFormType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\NumberType; +use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -25,7 +26,11 @@ class ResourceKindType extends AbstractType { $builder ->add('name', TranslatableStringFormType::class, [ - 'label' => 'Nom', + 'label' => 'Title', + ]) + ->add('kind', TextType::class, [ + 'label' => 'budget.admin.form.Resource_kind_key', + 'help' => 'budget.admin.form.This kind must contains only alphabeticals characters, and dashes. This string is in use during document generation. Changes may have side effect on document' ]) ->add('ordering', NumberType::class) ->add('isActive', CheckboxType::class, [ diff --git a/src/Bundle/ChillBudgetBundle/Resources/views/Admin/Charge/index.html.twig b/src/Bundle/ChillBudgetBundle/Resources/views/Admin/Charge/index.html.twig index 2486aaecf..4f56c92cb 100644 --- a/src/Bundle/ChillBudgetBundle/Resources/views/Admin/Charge/index.html.twig +++ b/src/Bundle/ChillBudgetBundle/Resources/views/Admin/Charge/index.html.twig @@ -19,7 +19,10 @@ {% for entity in entities %}
{{ entity.kind }}
+