@@ -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 }
0 commit comments