From ef5977bcfe21fe21df337305915511036487093b Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Mon, 25 Apr 2022 18:18:48 +0200 Subject: [PATCH] allow changing calendar entry title (#3272) --- src/Calendar/CalendarService.php | 1 + .../SystemConfigurationController.php | 5 ++ src/DependencyInjection/Configuration.php | 4 ++ src/Form/Type/CalendarTitlePatternType.php | 63 +++++++++++++++++++ templates/calendar/user.html.twig | 32 +++++++++- .../DependencyInjection/AppExtensionTest.php | 1 + .../DependencyInjection/ConfigurationTest.php | 1 + translations/system-configuration.de.xlf | 6 +- translations/system-configuration.en.xlf | 6 +- 9 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 src/Form/Type/CalendarTitlePatternType.php diff --git a/src/Calendar/CalendarService.php b/src/Calendar/CalendarService.php index ec55fe37..52c7e536 100644 --- a/src/Calendar/CalendarService.php +++ b/src/Calendar/CalendarService.php @@ -114,6 +114,7 @@ final class CalendarService 'timeframeBegin' => $this->configuration->getCalendarTimeframeBegin(), 'timeframeEnd' => $this->configuration->getCalendarTimeframeEnd(), 'dragDropAmount' => $this->configuration->getCalendarDragAndDropMaxEntries(), + 'entryTitlePattern' => $this->configuration->find('calendar.title_pattern'), ]; $event = new CalendarConfigurationEvent($config); diff --git a/src/Controller/SystemConfigurationController.php b/src/Controller/SystemConfigurationController.php index b5e3b9c4..377348d2 100644 --- a/src/Controller/SystemConfigurationController.php +++ b/src/Controller/SystemConfigurationController.php @@ -16,6 +16,7 @@ use App\Form\Model\SystemConfiguration as SystemConfigurationModel; use App\Form\SystemConfigurationForm; use App\Form\Type\ActivityTypePatternType; use App\Form\Type\ArrayToCommaStringType; +use App\Form\Type\CalendarTitlePatternType; use App\Form\Type\CustomerTypePatternType; use App\Form\Type\DatePickerType; use App\Form\Type\DateTimeTextType; @@ -623,6 +624,10 @@ final class SystemConfigurationController extends AbstractController ->setTranslationDomain('system-configuration') ->setType(IntegerType::class) ->setConstraints([new Range(['min' => 0, 'max' => 20]), new NotNull()]), + (new Configuration()) + ->setName('calendar.title_pattern') + ->setTranslationDomain('system-configuration') + ->setType(CalendarTitlePatternType::class), ]), (new SystemConfigurationModel('branding')) ->setConfiguration([ diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index a0353fbe..86c3f500 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -429,6 +429,10 @@ class Configuration implements ConfigurationInterface ->thenInvalid('The dragdrop_amount must be between 0 and 20') ->end() ->end() + ->enumNode('title_pattern') + ->values(['{activity}', '{project}', '{customer}', '{description}']) + ->defaultValue('{activity}') + ->end() ->end() ; diff --git a/src/Form/Type/CalendarTitlePatternType.php b/src/Form/Type/CalendarTitlePatternType.php new file mode 100644 index 00000000..b99518a7 --- /dev/null +++ b/src/Form/Type/CalendarTitlePatternType.php @@ -0,0 +1,63 @@ +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; + } +} diff --git a/templates/calendar/user.html.twig b/templates/calendar/user.html.twig index 9543226c..8b89cb22 100644 --- a/templates/calendar/user.html.twig +++ b/templates/calendar/user.html.twig @@ -62,6 +62,10 @@