Debian Codegraph @

skins/MinervaNeue/includes/Menu/PageActions/PageActionsDirector.php

raw symbols SCIP
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\PageActions;
21
22 use MessageLocalizer;
23
24 /**
25 * Director responsible for building Page Actions menu.
26 * This class is stateless.
27 */
28 final class PageActionsDirector {
29
30 private ToolbarBuilder $toolbarBuilder;
31 private IOverflowBuilder $overflowBuilder;
32 private MessageLocalizer $messageLocalizer;
33
34 /**
35 * Director responsible for Page Actions menu building
36 *
37 * @param ToolbarBuilder $toolbarBuilder
38 * @param IOverflowBuilder $overflowBuilder The overflow menu builder
39 * @param MessageLocalizer $messageLocalizer Message localizer used to translate texts
40 */
41 public function __construct(
42 ToolbarBuilder $toolbarBuilder,
43 IOverflowBuilder $overflowBuilder,
44 MessageLocalizer $messageLocalizer
45 ) {
46 $this->toolbarBuilder = $toolbarBuilder;
47 $this->overflowBuilder = $overflowBuilder;
48 $this->messageLocalizer = $messageLocalizer;
49 }
50
51 /**
52 * Build the menu data array that can be passed to views/javascript
53 * @param array $toolbox An array of common toolbox items from the sidebar menu
54 * @param array $actions An array of actions usually bucketed under the more menu
55 * @param array $views An array of actions usually bucketed under the view menu
56 * @return array
57 */
58 public function buildMenu( array $toolbox, array $actions, array $views ): array {
59 $toolbar = $this->toolbarBuilder->getGroup( $actions, $views );
60 $overflowMenu = $this->overflowBuilder->getGroup( $toolbox, $actions );
61
62 $menu = [
63 'toolbar' => $toolbar->getEntries()
64 ];
65 if ( $overflowMenu->hasEntries() ) {
66 // See includes/Skins/ToggleList.
67 $toggleID = 'page-actions-overflow-toggle';
68 $checkboxID = 'page-actions-overflow-checkbox';
69 $menu[ 'overflowMenu' ] = [
70 'item-id' => 'page-actions-overflow',
71 'checkboxID' => $checkboxID,
72 'toggleID' => $toggleID,
73 'data-btn' => [
74 'tag-name' => 'label',
75 'data-icon' => [
76 'icon' => 'ellipsis',
77 ],
78 'classes' => 'toggle-list__toggle',
79 'array-attributes' => [
80 [
81 'key' => 'id',
82 'value' => $toggleID,
83 ],
84 [
85 'key' => 'for',
86 'value' => $checkboxID,
87 ],
88 [
89 'key' => 'aria-hidden',
90 'value' => 'true'
91 ],
92 [
93 'key' => 'data-event-name',
94 'value' => 'ui.overflowmenu',
95 ],
96 ],
97 // class = toggle-list__toggle {{toggleClass}}
98 // data-event-name="{{analyticsEventName}}">
99 'label' => $this->messageLocalizer->msg( 'minerva-page-actions-overflow' ),
100 ],
101 'listID' => $overflowMenu->getId(),
102 'listClass' => 'page-actions-overflow-list toggle-list__list--drop-down',
103 'items' => $overflowMenu->getEntries()
104 ];
105 }
106 return $menu;
107 }
108
109 }