44
55namespace Terminal42 \NotificationCenterBundle \EventListener \Backend \DataContainer ;
66
7- use Contao \CoreBundle \DataContainer \PaletteManipulator ;
87use Contao \CoreBundle \DependencyInjection \Attribute \AsCallback ;
98use Contao \DataContainer ;
109use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
@@ -21,30 +20,19 @@ public function __construct(
2120 ) {
2221 }
2322
24- #[AsCallback(table: 'tl_module ' , target: 'config.onload ' )]
25- public function onLoadCallback (DataContainer $ dc ): void
23+ /**
24+ * @param array<string, mixed> $attributes
25+ *
26+ * @return array<string, mixed>
27+ */
28+ #[AsCallback(table: 'tl_module ' , target: 'fields.nc_notification.attributes ' )]
29+ public function onAttributesCallback (array $ attributes , DataContainer $ dc ): array
2630 {
27- if (null === ( $ moduleConfig = $ this -> configLoader -> loadModule (( int ) $ dc -> id )) ) {
28- return ;
31+ if (' newsletterSubscribeNotificationCenter ' === $ dc -> getCurrentRecord ()[ ' type ' ] ) {
32+ $ attributes [ ' mandatory ' ] = true ;
2933 }
3034
31- switch ($ moduleConfig ->getType ()) {
32- case 'lostPasswordNotificationCenter ' :
33- $ this ->handleLostPasswordModule ();
34- break ;
35- case 'registrationNotificationCenter ' :
36- $ this ->handleRegistrationModule ();
37- break ;
38- case 'personalData ' :
39- $ this ->handlePersonalDataModule ();
40- break ;
41- case 'newsletterSubscribeNotificationCenter ' :
42- $ this ->handleNewsletterSubscribeModule ();
43- break ;
44- case 'newsletterUnsubscribeNotificationCenter ' :
45- $ this ->handleNewsletterUnubscribeModule ();
46- break ;
47- }
35+ return $ attributes ;
4836 }
4937
5038 /**
@@ -68,61 +56,4 @@ public function onNotificationOptionsCallback(DataContainer $dc): array
6856
6957 return [];
7058 }
71-
72- private function handleLostPasswordModule (): void
73- {
74- $ GLOBALS ['TL_DCA ' ]['tl_module ' ]['palettes ' ]['lostPasswordNotificationCenter ' ] = $ GLOBALS ['TL_DCA ' ]['tl_module ' ]['palettes ' ]['lostPassword ' ];
75-
76- PaletteManipulator::create ()
77- ->addField ('nc_notification ' , 'reg_password ' , PaletteManipulator::POSITION_BEFORE )
78- ->addField ('nc_lost_password_jumpTo ' , 'email_legend ' , PaletteManipulator::POSITION_PREPEND )
79- ->removeField ('reg_password ' )
80- ->applyToPalette ('lostPasswordNotificationCenter ' , 'tl_module ' )
81- ;
82- }
83-
84- private function handleRegistrationModule (): void
85- {
86- $ GLOBALS ['TL_DCA ' ]['tl_module ' ]['palettes ' ]['registrationNotificationCenter ' ] = $ GLOBALS ['TL_DCA ' ]['tl_module ' ]['palettes ' ]['registration ' ];
87-
88- PaletteManipulator::create ()
89- ->addField ('nc_notification ' , 'reg_activate ' )
90- ->addField ('nc_registration_auto_activate ' , 'nc_notification ' )
91- ->removeField ('reg_activate ' )
92- ->applyToPalette ('registrationNotificationCenter ' , 'tl_module ' )
93- ;
94- }
95-
96- private function handlePersonalDataModule (): void
97- {
98- PaletteManipulator::create ()
99- ->addField ('nc_notification ' , 'config_legend ' , PaletteManipulator::POSITION_APPEND )
100- ->applyToPalette ('personalData ' , 'tl_module ' )
101- ;
102- }
103-
104- private function handleNewsletterSubscribeModule (): void
105- {
106- $ GLOBALS ['TL_DCA ' ]['tl_module ' ]['palettes ' ]['newsletterSubscribeNotificationCenter ' ] = $ GLOBALS ['TL_DCA ' ]['tl_module ' ]['palettes ' ]['subscribe ' ];
107- $ GLOBALS ['TL_DCA ' ]['tl_module ' ]['fields ' ]['nc_notification ' ]['eval ' ]['mandatory ' ] = true ;
108-
109- PaletteManipulator::create ()
110- ->addField ('nc_notification ' , 'email_legend ' , PaletteManipulator::POSITION_APPEND )
111- ->addField ('nc_activation_notification ' , 'nc_notification ' )
112- ->addField ('nc_newsletter_activation_jumpTo ' , 'redirect_legend ' , PaletteManipulator::POSITION_APPEND )
113- ->removeField ('nl_subscribe ' )
114- ->applyToPalette ('newsletterSubscribeNotificationCenter ' , 'tl_module ' )
115- ;
116- }
117-
118- private function handleNewsletterUnubscribeModule (): void
119- {
120- $ GLOBALS ['TL_DCA ' ]['tl_module ' ]['palettes ' ]['newsletterUnsubscribeNotificationCenter ' ] = $ GLOBALS ['TL_DCA ' ]['tl_module ' ]['palettes ' ]['unsubscribe ' ];
121-
122- PaletteManipulator::create ()
123- ->addField ('nc_notification ' , 'email_legend ' , PaletteManipulator::POSITION_APPEND )
124- ->removeField ('nl_unsubscribe ' )
125- ->applyToPalette ('newsletterUnsubscribeNotificationCenter ' , 'tl_module ' )
126- ;
127- }
12859}
0 commit comments