Release 2.17 (#4836)

see https://github.com/kimai/kimai/pull/4836
This commit is contained in:
Kevin Papst
2024-05-19 17:42:03 +02:00
committed by GitHub
parent 5f7114e008
commit 0c445d1bc4
41 changed files with 318 additions and 307 deletions

View File

@@ -45,29 +45,47 @@ final class TagArrayToStringTransformer implements DataTransformerInterface
*
* @see \Symfony\Bridge\Doctrine\Form\DataTransformer\CollectionToArrayTransformer::reverseTransform()
*
* @param string|null $value
* @param array<string>|string|null $value
* @return Tag[]
* @throws TransformationFailedException
*/
public function reverseTransform(mixed $value): mixed
public function reverseTransform(mixed $value): array
{
// check for empty tag list
if ('' === $value || null === $value) {
return [];
}
$names = array_filter(array_unique(array_map('trim', explode(',', $value))));
if (!\is_array($value)) {
$names = array_filter(array_unique(array_map('trim', explode(',', $value))));
} else {
$names = $value;
}
// get the current tags and find the new ones that should be created
$tags = $this->tagRepository->findBy(['name' => $names]);
if ($this->create) {
// works, because of the implicit case: (string) $tag
$newNames = array_diff($names, $tags);
$tags = [];
foreach ($names as $tagName) {
if ($tagName === null || $tagName === '') {
continue;
}
foreach ($newNames as $name) {
$tagName = trim($tagName);
$tag = null;
if (is_numeric($tagName)) {
$tag = $this->tagRepository->find($tagName);
}
if ($tag === null) {
$tag = $this->tagRepository->findTagByName($tagName);
}
// get the current tags and find the new ones that should be created
if ($this->create && $tag === null) {
$tag = new Tag();
$tag->setName(mb_substr($name, 0, 100));
$tag->setName(mb_substr($tagName, 0, 100));
$this->tagRepository->saveTag($tag);
}
if ($tag !== null) {
$tags[] = $tag;
}
}

View File

@@ -122,7 +122,7 @@ trait FormTrait
return;
}
$options['projects'] = $data['project'];
$options['projects'] = \is_string($data['project']) ? (int) $data['project'] : $data['project'];
$event->getForm()->add('activity', ActivityType::class, $options);
}

View File

@@ -139,7 +139,7 @@ trait ToolbarFormTrait
protected function addPageSizeChoice(FormBuilderInterface $builder): void
{
$builder->add('pageSize', PageSizeType::class);
$builder->add('size', PageSizeType::class);
}
protected function addUserRoleChoice(FormBuilderInterface $builder): void

View File

@@ -36,13 +36,15 @@ final class TagsSelectType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options): void
{
if (!$options['allow_create']) {
return;
}
$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use ($options) {
/** @var array<string> $tagIds */
$tagIds = $event->getData();
// this is mainly here, because the link from tags index page uses the non-array syntax
if (\is_string($tagIds) || \is_int($tagIds)) {
$tagIds = array_filter(array_unique(array_map('trim', explode(',', $tagIds))));
}
if (!\is_array($tagIds)) {
return;
}
@@ -59,13 +61,15 @@ final class TagsSelectType extends AbstractType
$tag = $this->tagRepository->findTagByName($tagId);
}
if ($tag === null) {
if ($options['allow_create'] && $tag === null) {
$tag = new Tag();
$tag->setName(mb_substr($tagId, 0, 100));
$tag->setName($tagId);
$this->tagRepository->saveTag($tag);
}
$tags[] = $tag->getId();
if ($tag !== null) {
$tags[] = $tag->getId();
}
}
$event->setData($tags);
@@ -79,6 +83,9 @@ final class TagsSelectType extends AbstractType
'class' => Tag::class,
'label' => 'tag',
'allow_create' => false,
'choice_value' => function (Tag $tag) {
return $tag->getId();
},
'choice_attr' => function (Tag $tag) {
$color = $tag->getColor();
if ($color === null) {