diff --git a/config/services.yml b/config/services.yml index 6c19443..c3e892b 100644 --- a/config/services.yml +++ b/config/services.yml @@ -16,6 +16,7 @@ services: - '@phpbb.wpn.form_helper' - '@language' - '@template' + - '@notification_manager' tags: - { name: event.listener } diff --git a/event/listener.php b/event/listener.php index c05ad5e..ddbceb9 100644 --- a/event/listener.php +++ b/event/listener.php @@ -17,6 +17,7 @@ use phpbb\controller\helper as controller_helper; use phpbb\webpushnotifications\form\form_helper; use phpbb\language\language; +use phpbb\notification\manager; use phpbb\template\template; /** @@ -27,10 +28,9 @@ class listener implements EventSubscriberInterface public static function getSubscribedEvents() { return [ - 'core.ucp_notifications_output_notification_types_modify_template_vars' => 'load_template_data', 'core.ucp_display_module_before' => 'load_language', 'core.acp_main_notice' => 'compatibility_notice', - 'core.page_header_after' => 'service_worker_url', + 'core.page_header_after' => [['load_template_data'], ['service_worker_url']], ]; } @@ -46,6 +46,9 @@ public static function getSubscribedEvents() /* @var template */ protected $template; + /* @var manager */ + protected $phpbb_notifications; + /** * Constructor * @@ -53,25 +56,30 @@ public static function getSubscribedEvents() * @param form_helper $form_helper Form helper object * @param language $language Language object * @param template $template Template object + * @param manager $phpbb_notifications Notifications manager object */ - public function __construct(controller_helper $controller_helper, form_helper $form_helper, language $language, template $template) + public function __construct(controller_helper $controller_helper, form_helper $form_helper, language $language, template $template, manager $phpbb_notifications) { $this->controller_helper = $controller_helper; $this->form_helper = $form_helper; $this->language = $language; $this->template = $template; + $this->phpbb_notifications = $phpbb_notifications; } /** * Load template data - * - * @param \phpbb\event\data $event */ - public function load_template_data($event) + public function load_template_data() { - if ($event['method_data']['id'] === 'notification.method.phpbb.wpn.webpush') + $methods = $this->phpbb_notifications->get_subscription_methods(); + if (array_key_exists('notification.method.phpbb.wpn.webpush', $methods)) { - $template_ary = $event['method_data']['method']->get_ucp_template_data($this->controller_helper, $this->form_helper); + if (!$this->language->is_set('NOTIFICATION_METHOD_PHPBB_WPN_WEBPUSH')) + { + $this->language->add_lang('webpushnotifications_module_ucp', 'phpbb/webpushnotifications'); + } + $template_ary = $methods['notification.method.phpbb.wpn.webpush']['method']->get_ucp_template_data($this->controller_helper, $this->form_helper); $this->template->assign_vars($template_ary); } } diff --git a/language/en/webpushnotifications_module_ucp.php b/language/en/webpushnotifications_module_ucp.php index efb7018..83d900c 100644 --- a/language/en/webpushnotifications_module_ucp.php +++ b/language/en/webpushnotifications_module_ucp.php @@ -39,8 +39,10 @@ $lang = array_merge($lang, [ 'NOTIFICATION_METHOD_PHPBB_WPN_WEBPUSH' => 'Web Push', + 'NOTIFY_WEBPUSH_ENABLE_SHORT' => 'Enable Web Push notifications', 'NOTIFY_WEBPUSH_ENABLE' => 'Enable receiving Web Push notifications', 'NOTIFY_WEBPUSH_ENABLE_EXPLAIN' => 'Enable receiving browser-based push notifications.
The notifications can be turned off at any time in your browser settings, by unsubscribing, or by disabling the push notifications below.', 'NOTIFY_WEBPUSH_SUBSCRIBE' => 'Subscribe', 'NOTIFY_WEBPUSH_UNSUBSCRIBE' => 'Unsubscribe', + 'NOTIFY_WEBPUSH_SUBSCRIBED' => 'Subscribed', ]); diff --git a/styles/prosilver/template/event/ucp_notifications_form_before.html b/styles/prosilver/template/event/overall_header_head_append.html similarity index 100% rename from styles/prosilver/template/event/ucp_notifications_form_before.html rename to styles/prosilver/template/event/overall_header_head_append.html diff --git a/styles/prosilver/theme/phpbb_wpn.css b/styles/prosilver/theme/phpbb_wpn.css index 0420db8..bffb320 100644 --- a/styles/prosilver/theme/phpbb_wpn.css +++ b/styles/prosilver/theme/phpbb_wpn.css @@ -10,3 +10,15 @@ .button.hidden { display: none; } + +.wpn-notification-dropdown-footer { + font-size: 12px; + border-top: solid 1px #b9b9b9; + display: flex; + justify-content: space-evenly; + padding: 5px; +} + +.wpn-notification-dropdown-footer button:disabled { + opacity: 0.7; +}