allow changing calendar entry title (#3272)

This commit is contained in:
Kevin Papst
2022-04-25 18:18:48 +02:00
committed by GitHub
parent e94d47bf0f
commit ef5977bcfe
9 changed files with 116 additions and 3 deletions

View File

@@ -0,0 +1,63 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* Select the pattern that will be used for calendar entry titles.
*/
class CalendarTitlePatternType extends AbstractType
{
public const PATTERN_CUSTOMER = '{customer}';
public const PATTERN_PROJECT = '{project}';
public const PATTERN_ACTIVITY = '{activity}';
public const PATTERN_DESCRIPTION = '{description}';
public const SPACER = ' - ';
public const PATTERN_ACTIVITY_DESCRIPTION = self::PATTERN_ACTIVITY . self::SPACER . self::PATTERN_DESCRIPTION;
public const PATTERN_PROJECT_DESCRIPTION = self::PATTERN_PROJECT . self::SPACER . self::PATTERN_DESCRIPTION;
public const PATTERN_CUSTOMER_DESCRIPTION = self::PATTERN_CUSTOMER . self::SPACER . self::PATTERN_DESCRIPTION;
private $translator;
public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}
public function configureOptions(OptionsResolver $resolver): void
{
$customer = $this->translator->trans('label.customer');
$project = $this->translator->trans('label.project');
$activity = $this->translator->trans('label.activity');
$description = $this->translator->trans('label.description');
$resolver->setDefaults([
'label' => 'label.choice_pattern',
'choices' => [
$activity => CalendarTitlePatternType::PATTERN_ACTIVITY,
$project => CalendarTitlePatternType::PATTERN_PROJECT,
$customer => CalendarTitlePatternType::PATTERN_CUSTOMER,
$description => CalendarTitlePatternType::PATTERN_DESCRIPTION,
$activity . self::SPACER . $description => CalendarTitlePatternType::PATTERN_ACTIVITY_DESCRIPTION,
$project . self::SPACER . $description => CalendarTitlePatternType::PATTERN_PROJECT_DESCRIPTION,
$customer . self::SPACER . $description => CalendarTitlePatternType::PATTERN_CUSTOMER_DESCRIPTION,
]
]);
}
public function getParent(): string
{
return ChoiceType::class;
}
}