Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 43 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
UserMenuDirector | |
0.00% |
0 / 43 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
renderMenuData | |
0.00% |
0 / 41 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | namespace MediaWiki\Minerva\Menu\User; |
21 | |
22 | use MediaWiki\Html\TemplateParser; |
23 | use MessageLocalizer; |
24 | |
25 | /** |
26 | * Director responsible for building the user menu. |
27 | */ |
28 | final class UserMenuDirector { |
29 | private IUserMenuBuilder $builder; |
30 | private MessageLocalizer $localizer; |
31 | |
32 | /** |
33 | * @param IUserMenuBuilder $builder |
34 | * @param MessageLocalizer $localizer |
35 | */ |
36 | public function __construct( IUserMenuBuilder $builder, MessageLocalizer $localizer ) { |
37 | $this->builder = $builder; |
38 | $this->localizer = $localizer; |
39 | } |
40 | |
41 | /** |
42 | * Build the menu data array that can be passed to views/javascript |
43 | * @param array $personalTools Personal tools list generated by Skin::buildPersonalUrls |
44 | * @return string|null |
45 | */ |
46 | public function renderMenuData( array $personalTools ): ?string { |
47 | $group = $this->builder->getGroup( $personalTools ); |
48 | $entries = $group->getEntries(); |
49 | |
50 | $templateParser = new TemplateParser( __DIR__ . '/../../Skins' ); |
51 | $toggleID = 'minerva-user-menu-toggle'; |
52 | $checkboxID = 'minerva-user-menu-checkbox'; |
53 | return !$entries |
54 | ? null |
55 | : $templateParser->processTemplate( 'ToggleList', [ |
56 | 'class' => 'minerva-user-menu', |
57 | 'checkboxID' => $checkboxID, |
58 | 'toggleID' => $toggleID, |
59 | 'data-btn' => [ |
60 | 'tag-name' => 'label', |
61 | 'data-icon' => [ |
62 | 'icon' => 'userAvatarOutline', |
63 | ], |
64 | 'classes' => 'toggle-list__toggle', |
65 | 'array-attributes' => [ |
66 | [ |
67 | 'key' => 'id', |
68 | 'value' => $toggleID, |
69 | ], |
70 | [ |
71 | 'key' => 'for', |
72 | 'value' => $checkboxID, |
73 | ], |
74 | [ |
75 | 'key' => 'aria-hidden', |
76 | 'value' => 'true' |
77 | ], |
78 | [ |
79 | 'key' => 'data-event-name', |
80 | 'value' => 'ui.usermenu', |
81 | ], |
82 | ], |
83 | 'label' => $this->localizer->msg( 'minerva-user-menu-button' )->escaped(), |
84 | ], |
85 | 'listID' => $group->getId(), |
86 | // See ToggleList/*.less. |
87 | 'listClass' => 'minerva-user-menu-list toggle-list__list--drop-down', |
88 | 'items' => $entries |
89 | ] ); |
90 | } |
91 | } |