From 07eb96116f5100127623131bf282ecaa38f9864c Mon Sep 17 00:00:00 2001 From: Camille Simiand <camille.simiand@tetras-libre.fr> Date: Tue, 1 Feb 2022 13:11:49 +0100 Subject: [PATCH] Add edit video url page, form and method --- src/Controller/ProjectController.php | 32 ++++++++++++++++++ src/Form/EditVideoUrlFormType.php | 38 ++++++++++++++++++++++ templates/capsule/create.html.twig | 4 ++- templates/project/edit_video_url.html.twig | 25 ++++++++++++++ translations/messages.en.yaml | 3 ++ translations/messages.fr.yaml | 3 ++ 6 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 src/Form/EditVideoUrlFormType.php create mode 100644 templates/project/edit_video_url.html.twig diff --git a/src/Controller/ProjectController.php b/src/Controller/ProjectController.php index 6fded99..e31747e 100644 --- a/src/Controller/ProjectController.php +++ b/src/Controller/ProjectController.php @@ -3,12 +3,17 @@ namespace App\Controller; use App\Entity\Capsule; +use App\Entity\PendingEditorInvitation; use App\Exception\ZipArchiveNotOpeningException; +use App\Form\EditVideoUrlFormType; +use App\Form\RemoveEditorFormType; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Bundle\FrameworkBundle\Translation\Translator; use Symfony\Component\Config\Util\Exception\XmlParsingException; use Symfony\Component\Filesystem\Exception\FileNotFoundException; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpFoundation\File\Exception\FileException; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Symfony\Contracts\Translation\TranslatorInterface; @@ -162,4 +167,31 @@ class ProjectController extends AbstractController ['override' => true] ); } + + /** + * @Route("/capsule/{capsule_id}/edit_video_url", name="edit_video_url") + */ + public function editVideoUrl(int $capsule_id, Request $request, TranslatorInterface $translator): Response + { + $form = $this->createForm(EditVideoUrlFormType::class); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $this->addFlash( + 'success', + $translator->trans( + 'editors.remove.pending_editor.success' + ) + ); + + return $this->redirectToRoute('capsule_list', [ + 'capsule_id' => $capsule_id + ]); + } + + return $this->render('project/edit_video_url.html.twig', [ + 'editVideoUrlForm' => $form->createView(), +// 'capsule_id' => $capsule_id + ]); + } } diff --git a/src/Form/EditVideoUrlFormType.php b/src/Form/EditVideoUrlFormType.php new file mode 100644 index 0000000..4c36f72 --- /dev/null +++ b/src/Form/EditVideoUrlFormType.php @@ -0,0 +1,38 @@ +<?php + +namespace App\Form; + +use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\EmailType; +use Symfony\Component\Form\Extension\Core\Type\SubmitType; +use Symfony\Component\Form\Extension\Core\Type\UrlType; +use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; +use Symfony\Component\Validator\Constraints\NotBlank; + +class EditVideoUrlFormType extends AbstractType +{ + public function buildForm(FormBuilderInterface $builder, array $options): void + { + $builder + ->add( + 'video_url', + UrlType::class, + [ + 'constraints' => [new NotBlank(['message' => 'capsule.video_url.not_blank'])], + 'label' => 'capsule.edit.video_url.text', + 'empty_data' => '' + ] + ) + ->add( + 'save', + SubmitType::class, + ['label' => 'general.save'] + ); + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([]); + } +} diff --git a/templates/capsule/create.html.twig b/templates/capsule/create.html.twig index 2c1cf8f..b6321af 100644 --- a/templates/capsule/create.html.twig +++ b/templates/capsule/create.html.twig @@ -9,7 +9,9 @@ <div> <div class="row w-100 gx-0"> <div class="row-title-box"> - <h3 class="row-title">Create a capsule</h3> + <h3 class="row-title"> + {{ 'capsule.create_capsule'|trans }} + </h3> </div> </div> diff --git a/templates/project/edit_video_url.html.twig b/templates/project/edit_video_url.html.twig new file mode 100644 index 0000000..7ccf3cf --- /dev/null +++ b/templates/project/edit_video_url.html.twig @@ -0,0 +1,25 @@ +{% extends 'layout.html.twig' %} + +{% block title %} + {{ 'capsule.edit.video_url.title'|trans }} +{% endblock %} + +{% block body %} + + <div> + <div class="row w-100 gx-0"> + <div class="row-title-box"> + <h3 class="row-title"> + {{ 'capsule.edit.video_url.title'|trans }} + </h3> + </div> + </div> + + {{ form_start(editVideoUrlForm, {'attr': {novalidate: 'novalidate', 'class': 'd-flex flex-column justify-content-center'}}) }} + {{ form_row(editVideoUrlForm.video_url, {'row_attr': {'class' : 'm-auto mb-4 col-6'}}) }} + {{ form_row(editVideoUrlForm.save, {'row_attr': {'class' : 'm-auto mb-5 col-2'}}) }} + {{ form_end(editVideoUrlForm) }} + + </div> + +{% endblock %} \ No newline at end of file diff --git a/translations/messages.en.yaml b/translations/messages.en.yaml index 91308a7..43cbb82 100644 --- a/translations/messages.en.yaml +++ b/translations/messages.en.yaml @@ -8,6 +8,7 @@ general: link_expire: This link will expire in %expirationDuration% greeting: Cheers! validate: Validate + save: Save login: account_disabled_feedback: Your user account is disabled. Please click on the link your receive by email to validate your registration. @@ -72,6 +73,8 @@ capsule: not_found: The capsule was not found video_url: link: Edit video URL + text: Enter a new video URL from Youtube or Vimeo + title: Edit video URL duplicate: link: Duplicate capsule title: Duplicate capsule diff --git a/translations/messages.fr.yaml b/translations/messages.fr.yaml index dcd52b4..27713bd 100644 --- a/translations/messages.fr.yaml +++ b/translations/messages.fr.yaml @@ -8,6 +8,7 @@ general: go_back_to_home_page: Page d'accueil cancel_button: Annuler validate: Valider + save: Enregistrer login: account_disabled_feedback: Le compte utilisateur a été désactivé. Veuillez cliquer sur le lien pour recevoir un courriel de validation @@ -69,6 +70,8 @@ capsule: not_found: La capsule n'existe pas video_url: link: Modifier l'URL de la vidéo + text: Saisir l'URL de la nouvelle vidéo Youtube ou Vimeo + title: Modifier l'URL de la vidéo duplicate: link: Dupliquer la capsule title: Dupliquer la capsule -- GitLab