|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NovaAdDirector\Nova\Resources; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use Laravel\Nova\Fields\Field; |
|
7
|
|
|
use Laravel\Nova\Fields\ID; |
|
8
|
|
|
use Laravel\Nova\Fields\Select; |
|
9
|
|
|
use Laravel\Nova\Fields\Text; |
|
10
|
|
|
use NovaAdDirector\NovaAdDirector; |
|
11
|
|
|
use NovaFlexibleContent\Flexible; |
|
12
|
|
|
|
|
13
|
|
|
trait HasAdConfiguration |
|
14
|
|
|
{ |
|
15
|
|
|
public static function label() |
|
16
|
|
|
{ |
|
17
|
|
|
return trans('nova-ad-director::resource.label'); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function fields(Request $request) |
|
|
|
|
|
|
21
|
|
|
{ |
|
22
|
|
|
return [ |
|
23
|
|
|
$this->fieldID(), |
|
24
|
|
|
$this->fieldKey(), |
|
25
|
|
|
$this->fieldLocation(), |
|
26
|
|
|
$this->fieldStatus(), |
|
27
|
|
|
$this->fieldConfiguration(), |
|
28
|
|
|
]; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function fieldID(): Field |
|
32
|
|
|
{ |
|
33
|
|
|
return ID::make()->sortable(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function fieldKey(): Field |
|
37
|
|
|
{ |
|
38
|
|
|
return Text::make(trans('nova-ad-director::resource.fields.key'), 'key') |
|
39
|
|
|
->sortable() |
|
40
|
|
|
->placeholder(implode(NovaAdDirector::$fallbackKeyConnector, ['header', 'page', 'contact'])) |
|
41
|
|
|
->rules('required', 'regex:/^[a-z0-9_\-'.NovaAdDirector::$fallbackKeyConnector.']+$/i', 'max:150') |
|
42
|
|
|
->readonly(!config('nova-ad-director.creatable')); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function fieldLocation(): Field |
|
46
|
|
|
{ |
|
47
|
|
|
return Text::make(trans('nova-ad-director::resource.fields.location'), 'location') |
|
48
|
|
|
->sortable() |
|
49
|
|
|
->rules('required', 'regex:/^[a-z0-9_-]+$/i', 'max:150') |
|
50
|
|
|
->readonly(!config('nova-ad-director.creatable')); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function fieldStatus(): Field |
|
54
|
|
|
{ |
|
55
|
|
|
return Select::make(trans('nova-ad-director::resource.fields.status'), 'status') |
|
56
|
|
|
->options(collect(config('nova-ad-director.statuses')) |
|
57
|
|
|
->mapWithKeys(fn ($status) => [$status => trans("nova-ad-director::resource.statuses.{$status}")]) |
|
58
|
|
|
->toArray()) |
|
59
|
|
|
->displayUsingLabels() |
|
60
|
|
|
->sortable() |
|
61
|
|
|
->rules('required'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function fieldConfiguration(): Field |
|
65
|
|
|
{ |
|
66
|
|
|
$field = Flexible::make('Configuration', 'configuration') |
|
67
|
|
|
->limit() |
|
68
|
|
|
->rules('required'); |
|
69
|
|
|
foreach (config('nova-ad-director.flexible.configuration.layouts') as $layout) { |
|
70
|
|
|
$field->addLayout($layout); |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return $field; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.