1 | <?php |
||
2 | |||
3 | /** |
||
4 | * This class contains a standard way of preparing the subsections of the menu |
||
5 | * |
||
6 | * @package ElkArte Forum |
||
7 | * @copyright ElkArte Forum contributors |
||
8 | * @license BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file) |
||
9 | * |
||
10 | * @version 2.0 dev |
||
11 | * |
||
12 | */ |
||
13 | |||
14 | namespace ElkArte\Menu; |
||
15 | |||
16 | /** |
||
17 | * Class MenuSubsection |
||
18 | * |
||
19 | * This class will set and access the menu subsection options. The supported options are: |
||
20 | * |
||
21 | * 'xyz' => [$txt['abc'], 'admin_forum', optional bool, 'enabled' => true/false, 'url' => getUrl()] |
||
22 | * $subsections sub array is both an unnamed index array and named array ... interpreted as follows, |
||
23 | * - string 0 => Label for this subsection |
||
24 | * - array 1 => Array of permissions to check for this subsection. |
||
25 | * - bool 2 => Optional. Is this the default subaction - if not set for any will default to first... |
||
26 | * - bool enabled => Enabled or not |
||
27 | * - array active => Show the button active for other subsections. |
||
28 | * - string url => Custom url for the subsection |
||
29 | * |
||
30 | * @package ElkArte\Menu |
||
31 | */ |
||
32 | class MenuSubsection extends MenuItem |
||
33 | { |
||
34 | /** @var bool $default Is this the default subaction - if not set for any will default to first... */ |
||
35 | protected $default = false; |
||
36 | |||
37 | /** @var string[] $active Set the button active for other subsections. */ |
||
38 | protected $active = []; |
||
39 | |||
40 | /** |
||
41 | * Check if the object is a default value. |
||
42 | 12 | * |
|
43 | * This method returns the value of the "default" property of the object. |
||
44 | 12 | * |
|
45 | * @return bool Returns true if the object is a default value, false otherwise. |
||
46 | */ |
||
47 | public function isDefault() |
||
48 | { |
||
49 | return $this->default; |
||
50 | } |
||
51 | |||
52 | 60 | /** |
|
53 | * Set the default value of the object. |
||
54 | 60 | * |
|
55 | * This method sets the value of the "default" property of the object. |
||
56 | 60 | * |
|
57 | * @param mixed $default The new default value to be set. |
||
58 | * @return $this This method returns the current instance of the object, allowing for method chaining. |
||
59 | */ |
||
60 | public function setDefault($default) |
||
61 | { |
||
62 | 60 | $this->default = $default; |
|
63 | |||
64 | 60 | return $this; |
|
65 | } |
||
66 | |||
67 | /** |
||
68 | * Get the value of the "active" property of the object. |
||
69 | * |
||
70 | * This method returns the value of the "active" property of the object. |
||
71 | * |
||
72 | 60 | * @return string[] |
|
73 | */ |
||
74 | 60 | public function getActive() |
|
75 | { |
||
76 | 60 | return $this->active; |
|
77 | } |
||
78 | |||
79 | /** |
||
80 | * Set the active state of the object. |
||
81 | * |
||
82 | * This method sets the value of the "active" property of the object. |
||
83 | * |
||
84 | * @param string[] $active The new active state of the object. |
||
85 | * |
||
86 | * @return $this The modified object instance. |
||
87 | */ |
||
88 | 60 | public function setActive($active) |
|
89 | { |
||
90 | $this->active = $active; |
||
91 | 60 | ||
92 | 60 | return $this; |
|
93 | 60 | } |
|
94 | |||
95 | /** |
||
96 | 60 | * Standard name for our function, but for subsections unique areas they are unnamed |
|
97 | * index values and have to be processed as such. |
||
98 | 10 | * |
|
99 | * @param array $arr |
||
100 | * @param string $sa |
||
101 | 60 | * |
|
102 | * @return MenuSubsection |
||
103 | */ |
||
104 | public function buildMoreFromArray($arr, $sa) |
||
105 | { |
||
106 | // These are special due to the non named index so there is no generic setter |
||
107 | $this->label = $arr[0]; |
||
108 | $this->permission = isset($arr[1]) ? (array) $arr[1] : []; |
||
109 | $this->default = isset($arr[2]) && (bool) $arr[2]; |
||
110 | |||
111 | // Support for boolean here, wrong but has been used |
||
112 | if ($this->getActive() === true) |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
113 | { |
||
114 | $this->setActive([$sa]); |
||
115 | } |
||
116 | |||
117 | return $this; |
||
118 | } |
||
119 | } |
||
120 |