1717use phpbb \controller \helper as controller_helper ;
1818use phpbb \webpushnotifications \form \form_helper ;
1919use phpbb \language \language ;
20+ use phpbb \notification \manager ;
2021use phpbb \template \template ;
2122
2223/**
@@ -27,10 +28,10 @@ class listener implements EventSubscriberInterface
2728 public static function getSubscribedEvents ()
2829 {
2930 return [
30- 'core.ucp_notifications_output_notification_types_modify_template_vars ' => 'load_template_data ' ,
3131 'core.ucp_display_module_before ' => 'load_language ' ,
3232 'core.acp_main_notice ' => 'compatibility_notice ' ,
33- 'core.page_header_after ' => 'service_worker_url ' ,
33+ 'core.page_header_after ' => 'load_template_data ' ,
34+ 'core.user_add_modify_notifications_data ' => 'add_user_notification_data ' ,
3435 ];
3536 }
3637
@@ -46,32 +47,40 @@ public static function getSubscribedEvents()
4647 /* @var template */
4748 protected $ template ;
4849
50+ /* @var manager */
51+ protected $ phpbb_notifications ;
52+
4953 /**
5054 * Constructor
5155 *
5256 * @param controller_helper $controller_helper Controller helper object
5357 * @param form_helper $form_helper Form helper object
5458 * @param language $language Language object
5559 * @param template $template Template object
60+ * @param manager $phpbb_notifications Notifications manager object
5661 */
57- public function __construct (controller_helper $ controller_helper , form_helper $ form_helper , language $ language , template $ template )
62+ public function __construct (controller_helper $ controller_helper , form_helper $ form_helper , language $ language , template $ template, manager $ phpbb_notifications )
5863 {
5964 $ this ->controller_helper = $ controller_helper ;
6065 $ this ->form_helper = $ form_helper ;
6166 $ this ->language = $ language ;
6267 $ this ->template = $ template ;
68+ $ this ->phpbb_notifications = $ phpbb_notifications ;
6369 }
6470
6571 /**
6672 * Load template data
67- *
68- * @param \phpbb\event\data $event
6973 */
70- public function load_template_data ($ event )
74+ public function load_template_data ()
7175 {
72- if ($ event ['method_data ' ]['id ' ] === 'notification.method.phpbb.wpn.webpush ' )
76+ $ methods = $ this ->phpbb_notifications ->get_subscription_methods ();
77+ if (array_key_exists ('notification.method.phpbb.wpn.webpush ' , $ methods ))
7378 {
74- $ template_ary = $ event ['method_data ' ]['method ' ]->get_ucp_template_data ($ this ->controller_helper , $ this ->form_helper );
79+ if (!$ this ->language ->is_set ('NOTIFICATION_METHOD_PHPBB_WPN_WEBPUSH ' ))
80+ {
81+ $ this ->language ->add_lang ('webpushnotifications_module_ucp ' , 'phpbb/webpushnotifications ' );
82+ }
83+ $ template_ary = $ methods ['notification.method.phpbb.wpn.webpush ' ]['method ' ]->get_ucp_template_data ($ this ->controller_helper , $ this ->form_helper );
7584 $ this ->template ->assign_vars ($ template_ary );
7685 }
7786 }
@@ -93,13 +102,22 @@ public function compatibility_notice()
93102 }
94103
95104 /**
96- * Generate service worker URL globally for update
105+ * Add default web push notification settings for new users
106+ *
107+ * @param \phpbb\event\data $event The event object
108+ * @return void
97109 */
98- public function service_worker_url ( )
110+ public function add_user_notification_data ( $ event )
99111 {
100- if (!$ this ->template ->retrieve_var ('U_WEBPUSH_WORKER_URL ' ))
101- {
102- $ this ->template ->assign_var ('U_WEBPUSH_WORKER_URL ' , $ this ->controller_helper ->route ('phpbb_webpushnotifications_ucp_push_worker_controller ' ));
103- }
112+ $ notifications_data = $ event ['notifications_data ' ];
113+ $ notifications_data [] = [
114+ 'item_type ' => 'notification.type.quote ' ,
115+ 'method ' => 'notification.method.phpbb.wpn.webpush ' ,
116+ ];
117+ $ notifications_data [] = [
118+ 'item_type ' => 'notification.type.pm ' ,
119+ 'method ' => 'notification.method.phpbb.wpn.webpush ' ,
120+ ];
121+ $ event ['notifications_data ' ] = $ notifications_data ;
104122 }
105123}
0 commit comments