Support visibility for tags (#4086)

This commit is contained in:
Kevin Papst
2023-06-09 17:07:49 +02:00
committed by GitHub
parent 6e781b59e2
commit 2e2bf986a4
17 changed files with 246 additions and 161 deletions

View File

@@ -10,6 +10,7 @@
namespace App\Form;
use App\Entity\Tag;
use App\Form\Type\YesNoType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
@@ -32,6 +33,10 @@ class TagEditForm extends AbstractType
'description' => 'The tag name (forbidden character: comma)',
],
])
->add('visible', YesNoType::class, [
'label' => 'visible',
'help' => 'help.visible',
])
;
$this->addColor($builder);
}

View File

@@ -23,6 +23,7 @@ final class TagToolbarForm extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$this->addVisibilityChoice($builder);
$this->addSearchTermInputField($builder);
$this->addPageSizeChoice($builder);
$this->addHiddenPagination($builder);

View File

@@ -59,6 +59,7 @@ final class TagsSelectType extends AbstractType
}
$newData = [];
/** @var array<string> $newNames */
$newNames = [];
foreach ($tagIds as $tag) {
if (!\in_array($tag, $foundIds, true)) {
@@ -68,8 +69,10 @@ final class TagsSelectType extends AbstractType
}
}
// in case someone is using tags like "1234" this can interfere with the ID
$tags = $this->tagRepository->findTagsByName($newNames);
// 1. in case someone is using tags like "1234" this can interfere with the ID
// 2. if we would load only visible tags, we would try to create new ones below
// and that would trigger the unique constraint
$tags = $this->tagRepository->findTagsByName($newNames, null);
$foundTagNames = [];
foreach ($tags as $tag) {
$newData[] = (string) $tag->getId();