Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
OverflowMenuItem | |
0.00% |
0 / 15 |
|
0.00% |
0 / 4 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
jsonSerialize | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
getId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getWeight | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\DiscussionTools; |
4 | |
5 | use JsonSerializable; |
6 | |
7 | /** |
8 | * Item to go into the DiscussionTools overflow menu, as an OO.ui.MenuOptionWidget object. |
9 | */ |
10 | class OverflowMenuItem implements JsonSerializable { |
11 | |
12 | private string $icon; |
13 | private string $label; |
14 | private array $data; |
15 | private string $id; |
16 | private int $weight; |
17 | |
18 | /** |
19 | * @param string $id A unique identifier for the menu item, e.g. 'edit' or 'reportincident' |
20 | * @param string $icon An OOUI icon name. |
21 | * @param string $label A rendered string to use as the label for the item. |
22 | * @param int $weight Sorting weight. Higher values will push the item further up the menu. |
23 | * @param array $data Data to include with the menu item. Will be accessible via getData() on the |
24 | * OOUI MenuOptionWidget in client-side code. |
25 | */ |
26 | public function __construct( |
27 | string $id, |
28 | string $icon, |
29 | string $label, |
30 | int $weight = 0, |
31 | array $data = [] |
32 | ) { |
33 | $this->id = $id; |
34 | $this->icon = $icon; |
35 | $this->label = $label; |
36 | $this->weight = $weight; |
37 | $this->data = $data; |
38 | } |
39 | |
40 | public function jsonSerialize(): array { |
41 | $data = $this->data; |
42 | // Add 'id' into the 'data' array, for easier access with OOUI's getData() method |
43 | $data['id'] = $this->id; |
44 | return [ |
45 | 'id' => $this->id, |
46 | 'data' => $data, |
47 | 'icon' => $this->icon, |
48 | 'label' => $this->label, |
49 | ]; |
50 | } |
51 | |
52 | public function getId(): string { |
53 | return $this->id; |
54 | } |
55 | |
56 | public function getWeight(): int { |
57 | return $this->weight; |
58 | } |
59 | } |