Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
MentorUserOptionsHooks | |
0.00% |
0 / 12 |
|
0.00% |
0 / 3 |
12 | |
0.00% |
0 / 1 |
onGetPreferences | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
onUserGetDefaultOptions | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
onResourceLoaderExcludeUserOptions | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\Mentorship\Hooks; |
4 | |
5 | use GrowthExperiments\MentorDashboard\MentorTools\MentorStatusManager; |
6 | use GrowthExperiments\Mentorship\MentorPageMentorManager; |
7 | use MediaWiki\Preferences\Hook\GetPreferencesHook; |
8 | use MediaWiki\ResourceLoader\Context; |
9 | use MediaWiki\ResourceLoader\Hook\ResourceLoaderExcludeUserOptionsHook; |
10 | use MediaWiki\User\Hook\UserGetDefaultOptionsHook; |
11 | |
12 | /** |
13 | * Mentorship-related hooks that touch user-preferences |
14 | * |
15 | * Many mentorship hooks depend on MentorManager, which depends on session. User option related |
16 | * hooks must run before MentorManager has a chance, so we keep them separately. |
17 | */ |
18 | class MentorUserOptionsHooks implements |
19 | GetPreferencesHook, |
20 | UserGetDefaultOptionsHook, |
21 | ResourceLoaderExcludeUserOptionsHook |
22 | { |
23 | |
24 | /** @inheritDoc */ |
25 | public function onGetPreferences( $user, &$preferences ) { |
26 | $preferences[ MentorPageMentorManager::MENTORSHIP_ENABLED_PREF ] = [ |
27 | 'type' => 'api' |
28 | ]; |
29 | $preferences[ MentorStatusManager::MENTOR_AWAY_TIMESTAMP_PREF ] = [ |
30 | 'type' => 'api', |
31 | ]; |
32 | } |
33 | |
34 | /** |
35 | * @inheritDoc |
36 | */ |
37 | public function onUserGetDefaultOptions( &$defaultOptions ) { |
38 | $defaultOptions += [ |
39 | MentorPageMentorManager::MENTORSHIP_ENABLED_PREF => 1, |
40 | ]; |
41 | } |
42 | |
43 | /** @inheritDoc */ |
44 | public function onResourceLoaderExcludeUserOptions( |
45 | array &$keysToExclude, |
46 | Context $context |
47 | ): void { |
48 | $keysToExclude = array_merge( $keysToExclude, [ |
49 | MentorStatusManager::MENTOR_AWAY_TIMESTAMP_PREF, |
50 | ] ); |
51 | } |
52 | |
53 | } |