Release 2.11 (#4580)

This commit is contained in:
Kevin Papst
2024-02-02 13:52:24 +01:00
committed by GitHub
parent a9a32c83ac
commit 49e69d1ae3
55 changed files with 347 additions and 264 deletions

View File

@@ -16,10 +16,17 @@ use Symfony\Component\Form\Exception\TransformationFailedException;
final class TagArrayToStringTransformer implements DataTransformerInterface
{
private bool $create = true;
public function __construct(private TagRepository $tagRepository)
{
}
public function setCreate(bool $create): void
{
$this->create = $create;
}
/**
* Transforms an array of tags to a string.
*
@@ -55,15 +62,17 @@ final class TagArrayToStringTransformer implements DataTransformerInterface
// get the current tags and find the new ones that should be created
$tags = $this->tagRepository->findBy(['name' => $names]);
// works, because of the implicit case: (string) $tag
$newNames = array_diff($names, $tags);
if ($this->create) {
// works, because of the implicit case: (string) $tag
$newNames = array_diff($names, $tags);
foreach ($newNames as $name) {
$tag = new Tag();
$tag->setName(mb_substr($name, 0, 100));
$tags[] = $tag;
foreach ($newNames as $name) {
$tag = new Tag();
$tag->setName(mb_substr($name, 0, 100));
$tags[] = $tag;
// new tags persist automatically thanks to the cascade={"persist"}
// new tags persist automatically thanks to the cascade={"persist"}
}
}
return $tags;

View File

@@ -36,7 +36,7 @@ final class SearchTermType extends AbstractType
'placeholder' => 'search',
],
'constraints' => [
new Length(['min' => 3])
new Length(['min' => 2])
],
]);
}

View File

@@ -30,9 +30,12 @@ final class TagsInputType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->addModelTransformer(new CollectionToArrayTransformer(), true)
->addModelTransformer($this->transformer, true);
if ($options['allow_create'] === false) {
$this->transformer->setCreate(false);
}
$builder->addModelTransformer(new CollectionToArrayTransformer(), true);
$builder->addModelTransformer($this->transformer, true);
}
public function configureOptions(OptionsResolver $resolver): void