Merge pull request #6607 from wallabag/improve-too-much-tags

Add flash message when we try to add too much tags
This commit is contained in:
Kevin Decherf 2023-06-13 13:11:43 +02:00 committed by GitHub
commit e3f7df3ae2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 2 deletions

View file

@ -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()]));
}

View file

@ -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)
{

View file

@ -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.