diff --git a/Controller/DocumentPersonController.php b/Controller/DocumentPersonController.php index 56b6feb91..0ff91e853 100644 --- a/Controller/DocumentPersonController.php +++ b/Controller/DocumentPersonController.php @@ -13,6 +13,7 @@ use Chill\PersonBundle\Entity\Person; use Symfony\Component\Security\Core\Role\Role; use Chill\PersonBundle\Security\Authorization\PersonVoter; use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter; +use Symfony\Component\Translation\TranslatorInterface; /** * @Route("/{_locale}/person/{person}/document") @@ -21,6 +22,18 @@ use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter; */ class DocumentPersonController extends Controller { + + /** + * + * @var TranslatorInterface + */ + protected $translator; + + public function __construct(TranslatorInterface $translator) + { + $this->translator = $translator; + } + /** * @Route("/", name="person_document_index", methods="GET") */ @@ -84,8 +97,12 @@ class DocumentPersonController extends Controller $em = $this->getDoctrine()->getManager(); $em->persist($document); $em->flush(); + + $this->addFlash('success', $this->translator->trans("The document is successfully registered")); return $this->redirectToRoute('person_document_index', ['person' => $person->getId()]); + } elseif ($form->isSubmitted() and !$form->isValid()) { + $this->addFlash('error', $this->translator->trans("This form contains errors")); } return $this->render('ChillDocStoreBundle:PersonDocument:new.html.twig', [ @@ -128,10 +145,14 @@ class DocumentPersonController extends Controller if ($form->isSubmitted() && $form->isValid()) { $this->getDoctrine()->getManager()->flush(); + + $this->addFlash('success', $this->translator->trans("The document is successfully updated")); return $this->redirectToRoute( 'person_document_edit', ['id' => $document->getId(), 'person' => $person->getId()]); + } elseif ($form->isSubmitted() and !$form->isValid()) { + $this->addFlash('error', $this->translator->trans("This form contains errors")); } return $this->render( diff --git a/DependencyInjection/ChillDocStoreExtension.php b/DependencyInjection/ChillDocStoreExtension.php index e57851427..86da6ac79 100644 --- a/DependencyInjection/ChillDocStoreExtension.php +++ b/DependencyInjection/ChillDocStoreExtension.php @@ -27,6 +27,7 @@ class ChillDocStoreExtension extends Extension implements PrependExtensionInterf $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yml'); $loader->load('services/media.yml'); + $loader->load('services/controller.yml'); } diff --git a/Entity/Document.php b/Entity/Document.php index 1cfa94d8e..ee744fbfa 100644 --- a/Entity/Document.php +++ b/Entity/Document.php @@ -6,7 +6,8 @@ use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use Chill\MainBundle\Entity\HasScopeInterface; use Chill\MainBundle\Entity\User; - +use ChampsLibres\AsyncUploaderBundle\Validator\Constraints\AsyncFileExists; +use Symfony\Component\Validator\Constraints as Assert; /** * @ORM\MappedSuperclass() @@ -22,6 +23,9 @@ class Document implements HasScopeInterface /** * @ORM\Column(type="text") + * @Assert\Length( + * min=2, max=250 + * ) */ private $title; @@ -44,6 +48,7 @@ class Document implements HasScopeInterface * targetEntity="Chill\DocStoreBundle\Entity\StoredObject", * cascade={"persist"} * ) + * @Assert\Valid() */ private $object; diff --git a/Entity/StoredObject.php b/Entity/StoredObject.php index b89ec3754..dde739ee1 100644 --- a/Entity/StoredObject.php +++ b/Entity/StoredObject.php @@ -6,6 +6,7 @@ namespace Chill\DocStoreBundle\Entity; use Doctrine\ORM\Mapping as ORM; use ChampsLibres\AsyncUploaderBundle\Model\AsyncFileInterface; +use ChampsLibres\AsyncUploaderBundle\Validator\Constraints\AsyncFileExists; /** * Represent a document stored in an object store @@ -14,6 +15,9 @@ use ChampsLibres\AsyncUploaderBundle\Model\AsyncFileInterface; * * @ORM\Entity() * @ORM\Table("chill_doc.stored_object") + * @AsyncFileExists( + * message="The file is not stored properly" + * ) */ class StoredObject implements AsyncFileInterface { diff --git a/Form/PersonDocumentType.php b/Form/PersonDocumentType.php index ebd4c5d9a..d99c7b2b8 100644 --- a/Form/PersonDocumentType.php +++ b/Form/PersonDocumentType.php @@ -65,7 +65,9 @@ class PersonDocumentType extends AbstractType ->add('description', TextareaType::class, [ 'required' => false ]) - ->add('object', StoredObjectType::class) + ->add('object', StoredObjectType::class, [ + 'error_bubbling' => true + ]) ->add('scope', ScopePickerType::class, [ 'center' => $options['center'], 'role' => $options['role'] diff --git a/Resources/config/services/controller.yml b/Resources/config/services/controller.yml new file mode 100644 index 000000000..379d36829 --- /dev/null +++ b/Resources/config/services/controller.yml @@ -0,0 +1,8 @@ +services: + Chill\DocStoreBundle\Controller\: + resource: '../../../Controller' + tags: ['controller.service_arguments'] + + Chill\DocStoreBundle\Controller\DocumentPersonController: + autowire: true + \ No newline at end of file diff --git a/Resources/translation/messages.yml b/Resources/translation/messages.yml new file mode 100644 index 000000000..68a2b380b --- /dev/null +++ b/Resources/translation/messages.yml @@ -0,0 +1,2 @@ +## YAML Template. +--- diff --git a/Resources/translation/validators.fr.yml b/Resources/translation/validators.fr.yml new file mode 100644 index 000000000..cf2283889 --- /dev/null +++ b/Resources/translation/validators.fr.yml @@ -0,0 +1 @@ +The file is not stored properly: Le fichier n'est pas téléchargé correctement diff --git a/Resources/views/PersonDocument/_form.html.twig b/Resources/views/PersonDocument/_form.html.twig deleted file mode 100644 index d5e483e36..000000000 --- a/Resources/views/PersonDocument/_form.html.twig +++ /dev/null @@ -1 +0,0 @@ -{{ form_widget(form) }} diff --git a/Resources/views/PersonDocument/edit.html.twig b/Resources/views/PersonDocument/edit.html.twig index a81705328..49cf1456d 100644 --- a/Resources/views/PersonDocument/edit.html.twig +++ b/Resources/views/PersonDocument/edit.html.twig @@ -17,14 +17,32 @@ {% extends "ChillPersonBundle::layout.html.twig" %} +{% import "@ChillDocStore/Macro/macro.html.twig" as m %} + {% set activeRouteKey = '' %} {% block title %}{{ 'Editing document for %name%'|trans({ '%name%': person.firstName|capitalize ~ ' ' ~ person.lastName } )|capitalize }}{% endblock %} {% block personcontent %}