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;