1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Terranet\Administrator\Traits\Module; |
4
|
|
|
|
5
|
|
|
use Terranet\Administrator\Architect; |
6
|
|
|
use Terranet\Administrator\Contracts\Module\Navigable; |
7
|
|
|
|
8
|
|
|
trait AllowsNavigation |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Cast to string |
12
|
|
|
* Make module Routable. |
13
|
|
|
* It allows referencing module object while generating routes. |
14
|
|
|
* |
15
|
|
|
* @return mixed |
16
|
|
|
*/ |
17
|
|
|
public function __toString() |
18
|
|
|
{ |
19
|
|
|
return $this->url(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The module singular title. |
24
|
|
|
* |
25
|
|
|
* @return mixed |
26
|
|
|
*/ |
27
|
|
|
public function singular() |
28
|
|
|
{ |
29
|
|
|
return str_singular($this->title()); |
|
|
|
|
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The module title. |
34
|
|
|
* |
35
|
|
|
* @return mixed |
36
|
|
|
*/ |
37
|
|
|
public function title() |
38
|
|
|
{ |
39
|
|
|
return $this->translator()->has($key = $this->translationKey()) |
|
|
|
|
40
|
|
|
? trans($key) |
|
|
|
|
41
|
|
|
: Architect::humanize($this); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Navigation container which Resource belongs to. |
46
|
|
|
* Available: sidebar, tools |
47
|
|
|
* |
48
|
|
|
* @return mixed |
49
|
|
|
*/ |
50
|
|
|
public function navigableIn() |
51
|
|
|
{ |
52
|
|
|
return Navigable::MENU_SIDEBAR; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Append default params to navigation link. |
57
|
|
|
* Useful for default filters, scopes, etc... |
58
|
|
|
* |
59
|
|
|
* @return array |
60
|
|
|
*/ |
61
|
|
|
public function navigableParams(): array |
62
|
|
|
{ |
63
|
|
|
return []; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Add resource to navigation if condition accepts. |
68
|
|
|
* |
69
|
|
|
* @return mixed |
70
|
|
|
*/ |
71
|
|
|
public function showIf() |
72
|
|
|
{ |
73
|
|
|
return ($guard = $this->guard()) && method_exists($guard, 'showIf') |
|
|
|
|
74
|
|
|
? $guard->showIf() |
75
|
|
|
: true; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Appends count of items to a navigation. |
80
|
|
|
* |
81
|
|
|
* @return bool |
82
|
|
|
*/ |
83
|
|
|
public function appendCount() |
84
|
|
|
{ |
85
|
|
|
return null; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Add resource to navigation as link or header. |
90
|
|
|
* |
91
|
|
|
* @return mixed |
92
|
|
|
*/ |
93
|
|
|
public function showAs() |
94
|
|
|
{ |
95
|
|
|
return Navigable::AS_LINK; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Navigation group which module belongs to. |
100
|
|
|
* |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
|
|
public function group() |
104
|
|
|
{ |
105
|
|
|
return trans('administrator::module.groups.resources'); |
|
|
|
|
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Resource order number. |
110
|
|
|
* |
111
|
|
|
* @return int |
112
|
|
|
*/ |
113
|
|
|
public function order() |
114
|
|
|
{ |
115
|
|
|
return null; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Attributes assigned to <a> element. |
120
|
|
|
* |
121
|
|
|
* @return mixed |
122
|
|
|
*/ |
123
|
2 |
|
public function linkAttributes() |
124
|
|
|
{ |
125
|
2 |
|
return ['icon' => null, 'id' => $this->url()]; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* The module url. |
130
|
|
|
* |
131
|
|
|
* @return mixed |
132
|
|
|
*/ |
133
|
|
|
public function url() |
134
|
|
|
{ |
135
|
|
|
return snake_case(class_basename($this)); |
|
|
|
|
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function translationKey() |
139
|
|
|
{ |
140
|
|
|
return sprintf('administrator::module.resources.%s', $this->url()); |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.