Skip to content

Commit 2894f88

Browse files
author
tchapi
committed
field edition
1 parent 7f3aa26 commit 2894f88

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

config/services.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ parameters:
99
timezone: '%env(APP_TIMEZONE)%'
1010
public_calendars_enabled: '%env(default:default_public_calendars_enabled:bool:PUBLIC_CALENDARS_ENABLED)%'
1111
default_public_calendars_enabled: "true"
12+
caldav_enabled: "%env(bool:CALDAV_ENABLED)%"
13+
carddav_enabled: "%env(bool:CARDDAV_ENABLED)%"
1214

1315
services:
1416
# default configuration for services in *this* file

src/Controller/Admin/AddressBookController.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,13 @@ public function addressbookCreate(ManagerRegistry $doctrine, Request $request, s
4848
$addressbook = new AddressBook();
4949
}
5050

51-
$form = $this->createForm(AddressBookType::class, $addressbook, ['new' => !$id]);
51+
$isBirthdayCalendarEnabled = $this->getParameter('caldav_enabled') && $this->getParameter('carddav_enabled');
5252

53+
$form = $this->createForm(AddressBookType::class, $addressbook, ['new' => !$id, 'birthday_calendar_enabled' => $isBirthdayCalendarEnabled]);
54+
55+
if ($isBirthdayCalendarEnabled) {
56+
$form->get('includedInBirthdayCalendar')->setData($addressbook->isIncludedInBirthdayCalendar());
57+
}
5358
$form->get('principalUri')->setData(Principal::PREFIX.$username);
5459

5560
$form->handleRequest($request);
@@ -62,8 +67,16 @@ public function addressbookCreate(ManagerRegistry $doctrine, Request $request, s
6267

6368
$this->addFlash('success', $trans->trans('addressbooks.saved'));
6469

65-
// Let's sync the user birthday calendar if needed
66-
$birthdayService->syncUser($username);
70+
if ($isBirthdayCalendarEnabled && true === $form->get('includedInBirthdayCalendar')->getData()) {
71+
$addressbook->setIncludedInBirthdayCalendar(true);
72+
} else {
73+
$addressbook->setIncludedInBirthdayCalendar(false);
74+
}
75+
76+
if ($isBirthdayCalendarEnabled) {
77+
// Let's sync the user birthday calendar if needed
78+
$birthdayService->syncUser($username);
79+
}
6780

6881
return $this->redirectToRoute('addressbook_index', ['username' => $username]);
6982
}
@@ -97,8 +110,11 @@ public function addressbookDelete(ManagerRegistry $doctrine, string $username, s
97110
$entityManager->flush();
98111
$this->addFlash('success', $trans->trans('addressbooks.deleted'));
99112

100-
// Let's sync the user birthday calendar if needed
101-
$birthdayService->syncUser($username);
113+
$isBirthdayCalendarEnabled = $this->getParameter('caldav_enabled') && $this->getParameter('carddav_enabled');
114+
if ($isBirthdayCalendarEnabled) {
115+
// Let's sync the user birthday calendar if needed
116+
$birthdayService->syncUser($username);
117+
}
102118

103119
return $this->redirectToRoute('addressbook_index', ['username' => $username]);
104120
}

src/Form/AddressBookType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,18 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
4242
->add('save', SubmitType::class, [
4343
'label' => 'save',
4444
]);
45+
46+
if (!$options['birthday_calendar_enabled']) {
47+
$builder->remove('includedInBirthdayCalendar');
48+
}
4549
}
4650

4751
public function configureOptions(OptionsResolver $resolver): void
4852
{
4953
$resolver->setDefaults([
5054
'new' => false,
5155
'data_class' => AddressBook::class,
56+
'birthday_calendar_enabled' => true,
5257
]);
5358
}
5459
}

0 commit comments

Comments
 (0)