1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Terranet\Administrator\Traits\Actions; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model as Eloquent; |
|
|
|
|
6
|
|
|
use Illuminate\Support\Str; |
7
|
|
|
|
8
|
|
|
trait Skeleton |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @return string |
12
|
|
|
*/ |
13
|
|
|
protected function type(): string |
14
|
|
|
{ |
15
|
|
|
return 'primary'; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Render action button. |
20
|
|
|
* |
21
|
|
|
* @param Eloquent $entity |
22
|
|
|
* @return string |
23
|
|
|
*/ |
24
|
|
|
public function render(Eloquent $entity = null) |
25
|
|
|
{ |
26
|
|
|
$action = app('scaffold.module')->url().'-'.$this->action($entity); |
|
|
|
|
27
|
|
|
$icon = ($i = $this->icon($entity)) ? "<i class=\"fa {$i}\"></i>" : ''; |
28
|
|
|
|
29
|
|
|
return |
30
|
|
|
<<<OUTPUT |
31
|
|
|
<a data-scaffold-action="{$action}" data-scaffold-key="{$this->entityKey($entity)}" href="{$this->route($entity)}" {$this->attributes($entity)}> |
|
|
|
|
32
|
|
|
{$icon}<span>{$this->name($entity)}</span> |
33
|
|
|
</a> |
34
|
|
|
OUTPUT; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Render action button. |
39
|
|
|
* |
40
|
|
|
* @param Eloquent $entity |
41
|
|
|
* @return string |
42
|
|
|
*/ |
43
|
|
|
public function renderBtn(Eloquent $entity = null) |
44
|
|
|
{ |
45
|
|
|
$action = app('scaffold.module')->url().'-'.$this->action($entity); |
|
|
|
|
46
|
|
|
$icon = ($i = $this->icon($entity)) ? "<i class=\"fa {$i}\"></i>" : ''; |
47
|
|
|
|
48
|
|
|
return |
49
|
|
|
<<<OUTPUT |
50
|
|
|
<a class="btn btn-{$this->type()}" data-scaffold-action="{$action}" data-scaffold-key="{$this->entityKey($entity)}" href="{$this->route($entity)}" {$this->attributes($entity)}> |
|
|
|
|
51
|
|
|
{$icon}<span>{$this->name($entity)}</span> |
52
|
|
|
</a> |
53
|
|
|
OUTPUT; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param Eloquent $entity |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
public function action(Eloquent $entity = null) |
|
|
|
|
61
|
|
|
{ |
62
|
|
|
return Str::snake(class_basename($this)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Action name. |
67
|
|
|
* |
68
|
|
|
* @param Eloquent $entity |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
public function name(Eloquent $entity = null) |
|
|
|
|
72
|
|
|
{ |
73
|
|
|
return app('translator')->has($key = $this->translationKey()) |
|
|
|
|
74
|
|
|
? trans($key) |
|
|
|
|
75
|
|
|
: Str::title(str_replace('_', ' ', Str::snake(class_basename($this)))); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param Eloquent $entity |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
public function icon(Eloquent $entity = null): string |
|
|
|
|
83
|
|
|
{ |
84
|
|
|
return 'fa-circle-thin'; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
|
|
protected function translationKey(): string |
91
|
|
|
{ |
92
|
|
|
$key = sprintf('administrator::actions.%s.%s', app('scaffold.module')->url(), Str::snake(class_basename($this))); |
|
|
|
|
93
|
|
|
|
94
|
|
|
if (!app('translator')->has($key)) { |
95
|
|
|
$key = sprintf('administrator::actions.global.%s', Str::snake(class_basename($this))); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return $key; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param null $entity |
|
|
|
|
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
|
|
protected function entityKey($entity = null): string |
106
|
|
|
{ |
107
|
|
|
return $entity ? $entity->getKey() : 'empty'; |
|
|
|
|
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths