mirror of
https://github.com/wallabag/wallabag.git
synced 2024-12-23 08:06:33 +00:00
Added flash message when we try to add to much tags
This commit is contained in:
parent
c4de437105
commit
96cf34f730
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\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
use Wallabag\CoreBundle\Entity\Entry;
|
use Wallabag\CoreBundle\Entity\Entry;
|
||||||
use Wallabag\CoreBundle\Entity\Tag;
|
use Wallabag\CoreBundle\Entity\Tag;
|
||||||
use Wallabag\CoreBundle\Form\Type\NewTagType;
|
use Wallabag\CoreBundle\Form\Type\NewTagType;
|
||||||
|
@ -39,7 +40,7 @@ class TagController extends AbstractController
|
||||||
*
|
*
|
||||||
* @return Response
|
* @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 = $this->createForm(NewTagType::class, new Tag());
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
@ -48,7 +49,13 @@ class TagController extends AbstractController
|
||||||
$tagsExploded = explode(',', $tags);
|
$tagsExploded = explode(',', $tags);
|
||||||
|
|
||||||
// avoid too much tag to be added
|
// 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()]));
|
return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ use Wallabag\CoreBundle\Entity\Tag;
|
||||||
class NewTagType extends AbstractType
|
class NewTagType extends AbstractType
|
||||||
{
|
{
|
||||||
public const MAX_LENGTH = 40;
|
public const MAX_LENGTH = 40;
|
||||||
|
public const MAX_TAGS = 5;
|
||||||
|
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||||
{
|
{
|
||||||
|
|
|
@ -683,6 +683,7 @@ flashes:
|
||||||
notice:
|
notice:
|
||||||
tag_added: Tag added
|
tag_added: Tag added
|
||||||
tag_renamed: 'Tag renamed'
|
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:
|
import:
|
||||||
notice:
|
notice:
|
||||||
failed: Import failed, please try again.
|
failed: Import failed, please try again.
|
||||||
|
|
Loading…
Reference in a new issue