From 96cf34f73043becb76a21b55b2a9823947488f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 13 Jun 2023 11:24:27 +0200 Subject: [PATCH] Added flash message when we try to add to much tags --- src/Wallabag/CoreBundle/Controller/TagController.php | 11 +++++++++-- src/Wallabag/CoreBundle/Form/Type/NewTagType.php | 1 + translations/messages.en.yml | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index acc8b8908..0063ec54a 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php @@ -11,6 +11,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; +use Symfony\Contracts\Translation\TranslatorInterface; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; use Wallabag\CoreBundle\Form\Type\NewTagType; @@ -39,7 +40,7 @@ class TagController extends AbstractController * * @return Response */ - public function addTagFormAction(Request $request, Entry $entry) + public function addTagFormAction(Request $request, Entry $entry, TranslatorInterface $translator) { $form = $this->createForm(NewTagType::class, new Tag()); $form->handleRequest($request); @@ -48,7 +49,13 @@ class TagController extends AbstractController $tagsExploded = explode(',', $tags); // avoid too much tag to be added - if (\count($tagsExploded) >= 5 || \strlen($tags) >= NewTagType::MAX_LENGTH) { + if (\count($tagsExploded) >= NewTagType::MAX_TAGS || \strlen($tags) >= NewTagType::MAX_LENGTH) { + $message = $translator->trans('flashes.tag.notice.too_much_tags', [ + '%tags%' => NewTagType::MAX_TAGS, + '%characters%' => NewTagType::MAX_LENGTH, + ]); + $this->addFlash('notice', $message); + return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()])); } diff --git a/src/Wallabag/CoreBundle/Form/Type/NewTagType.php b/src/Wallabag/CoreBundle/Form/Type/NewTagType.php index 60a478548..adff45cc2 100644 --- a/src/Wallabag/CoreBundle/Form/Type/NewTagType.php +++ b/src/Wallabag/CoreBundle/Form/Type/NewTagType.php @@ -12,6 +12,7 @@ use Wallabag\CoreBundle\Entity\Tag; class NewTagType extends AbstractType { public const MAX_LENGTH = 40; + public const MAX_TAGS = 5; public function buildForm(FormBuilderInterface $builder, array $options) { diff --git a/translations/messages.en.yml b/translations/messages.en.yml index de5483b39..30c925189 100644 --- a/translations/messages.en.yml +++ b/translations/messages.en.yml @@ -683,6 +683,7 @@ flashes: notice: tag_added: Tag added tag_renamed: 'Tag renamed' + too_much_tags: To avoid performance issues, you can't add more than %tags% tags at once or tags having more than %characters% characters. import: notice: failed: Import failed, please try again.