Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
MessageGroupSubscriptionHookHandler.php
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\MessageGroupProcessing;
5
6use MediaWiki\Extension\Notifications\Hooks\BeforeCreateEchoEventHook;
7use MediaWiki\Extension\Notifications\Hooks\EchoGetBundleRulesHook;
8use MediaWiki\Extension\Notifications\Model\Event;
10
17class MessageGroupSubscriptionHookHandler implements BeforeCreateEchoEventHook, EchoGetBundleRulesHook {
18
19 private const SUPPORTED_NOTIFICATION_TYPES = [ 'translate-mgs-message-added' ];
20
21 public static function registerHooks( array &$hooks ): void {
22 $hooks['BeforeCreateEchoEvent'][] = static function (
23 array &$notifications,
24 array &$notificationCategories,
25 array &$notificationIcons
26 ) {
27 Services::getInstance()->getMessageGroupSubscriptionHookHandler()->onBeforeCreateEchoEvent(
28 $notifications,
29 $notificationCategories,
30 $notificationIcons
31 );
32 };
33
34 $hooks['EchoGetBundleRules'][] = static function ( Event $event, string &$bundleKey ) {
35 Services::getInstance()->getMessageGroupSubscriptionHookHandler()->onEchoGetBundleRules(
36 $event,
37 $bundleKey
38 );
39 };
40 }
41
42 public function onBeforeCreateEchoEvent(
43 array &$notifications,
44 array &$notificationCategories,
45 array &$notificationIcons
46 ) {
47 $notificationCategories[ 'translate-message-group-subscription' ] = [
48 'tooltip' => 'echo-pref-tooltip-translate-message-group-subscription'
49 ];
50
51 $notifications[ 'translate-mgs-message-added' ] = [
52 'category' => 'translate-message-group-subscription',
53 'group' => 'neutral',
54 'section' => 'message',
55 'presentation-model' => MessageGroupSubscriptionPresentationModel::class,
56 'bundle' => [
57 'web' => true,
58 'expandable' => true,
59 ],
60 ];
61
62 $notificationIcons[ 'translate-mgs-icon' ] = [
63 'path' => 'Translate/resources/images/bell.svg'
64 ];
65 }
66
68 public function onEchoGetBundleRules( Event $event, string &$bundleKey ) {
69 if ( in_array( $event->getType(), self::SUPPORTED_NOTIFICATION_TYPES ) ) {
70 $bundleKey = $event->getExtraParam( 'groupId' );
71 }
72 }
73}
onEchoGetBundleRules(Event $event, string &$bundleKey)
Notifications for subscriptions are bundled by message group.
Minimal service container.
Definition Services.php:62