mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-26 19:11:07 +00:00
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:
commit
e3f7df3ae2
3 changed files with 11 additions and 2 deletions
|
@ -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()]));
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue