Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
92.86% |
26 / 28 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
VectorComponentMainMenu | |
92.86% |
26 / 28 |
|
0.00% |
0 / 2 |
6.01 | |
0.00% |
0 / 1 |
__construct | |
91.67% |
11 / 12 |
|
0.00% |
0 / 1 |
2.00 | |||
getTemplateData | |
93.75% |
15 / 16 |
|
0.00% |
0 / 1 |
4.00 |
1 | <?php |
2 | namespace MediaWiki\Skins\Vector\Components; |
3 | |
4 | use MediaWiki\Skins\Vector\Constants; |
5 | use MediaWiki\Skins\Vector\FeatureManagement\FeatureManager; |
6 | use MediaWiki\User\UserIdentity; |
7 | use MessageLocalizer; |
8 | use Skin; |
9 | |
10 | /** |
11 | * VectorComponentMainMenu component |
12 | */ |
13 | class VectorComponentMainMenu implements VectorComponent { |
14 | /** @var VectorComponent|null */ |
15 | private $optOut; |
16 | /** @var array */ |
17 | private $sidebarData; |
18 | /** @var array */ |
19 | private $languageData; |
20 | /** @var MessageLocalizer */ |
21 | private $localizer; |
22 | /** @var bool */ |
23 | private $isPinned; |
24 | /** @var VectorComponentPinnableHeader|null */ |
25 | private $pinnableHeader; |
26 | /** @var string */ |
27 | public const ID = 'vector-main-menu'; |
28 | |
29 | /** |
30 | * @param array $sidebarData |
31 | * @param array $languageData |
32 | * @param MessageLocalizer $localizer |
33 | * @param UserIdentity $user |
34 | * @param FeatureManager $featureManager |
35 | * @param Skin $skin |
36 | */ |
37 | public function __construct( |
38 | array $sidebarData, |
39 | array $languageData, |
40 | MessageLocalizer $localizer, |
41 | UserIdentity $user, |
42 | FeatureManager $featureManager, |
43 | Skin $skin |
44 | ) { |
45 | $this->sidebarData = $sidebarData; |
46 | $this->languageData = $languageData; |
47 | $this->localizer = $localizer; |
48 | $this->isPinned = $featureManager->isFeatureEnabled( Constants::FEATURE_MAIN_MENU_PINNED ); |
49 | |
50 | $this->pinnableHeader = new VectorComponentPinnableHeader( |
51 | $this->localizer, |
52 | $this->isPinned, |
53 | self::ID, |
54 | 'main-menu-pinned' |
55 | ); |
56 | |
57 | if ( $user->isRegistered() ) { |
58 | $this->optOut = new VectorComponentMainMenuActionOptOut( $skin ); |
59 | } |
60 | } |
61 | |
62 | /** |
63 | * @inheritDoc |
64 | */ |
65 | public function getTemplateData(): array { |
66 | $action = $this->optOut; |
67 | $pinnableHeader = $this->pinnableHeader; |
68 | |
69 | $portletsRest = []; |
70 | foreach ( $this->sidebarData[ 'array-portlets-rest' ] as $data ) { |
71 | $portletsRest[] = ( new VectorComponentMenu( $data ) )->getTemplateData(); |
72 | } |
73 | $firstPortlet = new VectorComponentMenu( $this->sidebarData['data-portlets-first'] ); |
74 | $languageMenu = new VectorComponentMenu( $this->languageData ); |
75 | |
76 | $pinnableContainer = new VectorComponentPinnableContainer( self::ID, $this->isPinned ); |
77 | $pinnableElement = new VectorComponentPinnableElement( self::ID ); |
78 | |
79 | return $pinnableElement->getTemplateData() + $pinnableContainer->getTemplateData() + [ |
80 | 'data-portlets-first' => $firstPortlet->getTemplateData(), |
81 | 'array-portlets-rest' => $portletsRest, |
82 | 'data-main-menu-action' => $action ? $action->getTemplateData() : null, |
83 | 'data-pinnable-header' => $pinnableHeader ? $pinnableHeader->getTemplateData() : null, |
84 | 'data-languages' => $languageMenu->getTemplateData(), |
85 | ]; |
86 | } |
87 | } |