Loading src/UnicaenUtilisateur/Form/Role/RoleForm.php +40 −20 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ namespace UnicaenUtilisateur\Form\Role; use Application\Entity\Db\UtilisateurRole; use DoctrineModule\Form\Element\ObjectSelect; use DoctrineModule\Validator\NoObjectExists; use DoctrineModule\Validator\UniqueObject; use UnicaenApp\Service\EntityManagerAwareTrait; use UnicaenUtilisateur\Entity\Db\UserInterface; Loading @@ -17,6 +18,7 @@ use Zend\Form\Form; use Zend\InputFilter\Factory; use Zend\Validator\Callback; use Zend\Validator\NotEmpty; use Zend\Validator\Regex; class RoleForm extends Form { Loading @@ -27,12 +29,6 @@ class RoleForm extends Form { $this->setAttribute('id', 'form-role'); /** nécessaire pour le validator @see \DoctrineModule\Validator\UniqueObject */ $this->add([ 'name' => 'id', 'type' => Hidden::class, ]); $this->add([ 'type' => Text::class, 'name' => 'libelle', Loading Loading @@ -157,17 +153,24 @@ class RoleForm extends Form ], ], [ 'name' => UniqueObject::class, 'name' => Callback::class, 'options' => [ 'object_manager' => $this->getEntityManager(), 'object_repository' => $this->roleService->getRepo(), 'use_context' => true, 'fields' => ['libelle'], 'messages' => [ UniqueObject::ERROR_OBJECT_NOT_UNIQUE => "Ce libellé est déjà utilisé dans l'application.", Callback::INVALID_VALUE => "Ce libellé est déjà utilisé pour un autre rôle.", ], 'callback' => function ($value, $context = []) { $role = $this->roleService->findByLibelle($value); if(!$role) { return true; } elseif($this->getObject()->getId() != null) { // modification return strtoupper($this->getObject()->getLibelle()) === strtoupper($value); } return false; }, 'break_chain_on_failure' => true, ], ], ] ], ], Loading @@ -184,17 +187,34 @@ class RoleForm extends Form ], ], [ 'name' => UniqueObject::class, 'name' => Regex::class, 'options' => [ 'pattern' => '/^[a-z0-9_-]+$/', 'messages' => [ Regex::NOT_MATCH => "Seuls les caractères suivants sont autorisés : [a-z, 0-9, _, -].", ], 'break_chain_on_failure' => true, ], ], [ 'name' => Callback::class, 'options' => [ 'object_manager' => $this->getEntityManager(), 'object_repository' => $this->roleService->getRepo(), 'use_context' => true, 'fields' => ['roleId'], 'messages' => [ UniqueObject::ERROR_OBJECT_NOT_UNIQUE => "Cet identifiant est déjà utilisé dans l'application.", Callback::INVALID_VALUE => "Cet identifiant est déjà utilisé pour un autre rôle.", ], 'callback' => function ($value, $context = []) { $role = $this->roleService->findByRoleId($value); if(!$role) { return true; } elseif($this->getObject()->getId() != null) { // modification return strtoupper($this->getObject()->getRoleId()) === strtoupper($value); } return false; }, 'break_chain_on_failure' => true, ], ], ] ], ], Loading Loading
src/UnicaenUtilisateur/Form/Role/RoleForm.php +40 −20 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ namespace UnicaenUtilisateur\Form\Role; use Application\Entity\Db\UtilisateurRole; use DoctrineModule\Form\Element\ObjectSelect; use DoctrineModule\Validator\NoObjectExists; use DoctrineModule\Validator\UniqueObject; use UnicaenApp\Service\EntityManagerAwareTrait; use UnicaenUtilisateur\Entity\Db\UserInterface; Loading @@ -17,6 +18,7 @@ use Zend\Form\Form; use Zend\InputFilter\Factory; use Zend\Validator\Callback; use Zend\Validator\NotEmpty; use Zend\Validator\Regex; class RoleForm extends Form { Loading @@ -27,12 +29,6 @@ class RoleForm extends Form { $this->setAttribute('id', 'form-role'); /** nécessaire pour le validator @see \DoctrineModule\Validator\UniqueObject */ $this->add([ 'name' => 'id', 'type' => Hidden::class, ]); $this->add([ 'type' => Text::class, 'name' => 'libelle', Loading Loading @@ -157,17 +153,24 @@ class RoleForm extends Form ], ], [ 'name' => UniqueObject::class, 'name' => Callback::class, 'options' => [ 'object_manager' => $this->getEntityManager(), 'object_repository' => $this->roleService->getRepo(), 'use_context' => true, 'fields' => ['libelle'], 'messages' => [ UniqueObject::ERROR_OBJECT_NOT_UNIQUE => "Ce libellé est déjà utilisé dans l'application.", Callback::INVALID_VALUE => "Ce libellé est déjà utilisé pour un autre rôle.", ], 'callback' => function ($value, $context = []) { $role = $this->roleService->findByLibelle($value); if(!$role) { return true; } elseif($this->getObject()->getId() != null) { // modification return strtoupper($this->getObject()->getLibelle()) === strtoupper($value); } return false; }, 'break_chain_on_failure' => true, ], ], ] ], ], Loading @@ -184,17 +187,34 @@ class RoleForm extends Form ], ], [ 'name' => UniqueObject::class, 'name' => Regex::class, 'options' => [ 'pattern' => '/^[a-z0-9_-]+$/', 'messages' => [ Regex::NOT_MATCH => "Seuls les caractères suivants sont autorisés : [a-z, 0-9, _, -].", ], 'break_chain_on_failure' => true, ], ], [ 'name' => Callback::class, 'options' => [ 'object_manager' => $this->getEntityManager(), 'object_repository' => $this->roleService->getRepo(), 'use_context' => true, 'fields' => ['roleId'], 'messages' => [ UniqueObject::ERROR_OBJECT_NOT_UNIQUE => "Cet identifiant est déjà utilisé dans l'application.", Callback::INVALID_VALUE => "Cet identifiant est déjà utilisé pour un autre rôle.", ], 'callback' => function ($value, $context = []) { $role = $this->roleService->findByRoleId($value); if(!$role) { return true; } elseif($this->getObject()->getId() != null) { // modification return strtoupper($this->getObject()->getRoleId()) === strtoupper($value); } return false; }, 'break_chain_on_failure' => true, ], ], ] ], ], Loading