|
1
|
|
|
<?php namespace Distilleries\Expendable\Http\Forms\Component; |
|
2
|
|
|
|
|
3
|
|
|
use Distilleries\Expendable\Helpers\StaticLabel; |
|
4
|
|
|
use \File; |
|
5
|
|
|
|
|
6
|
|
|
class ComponentForm extends \Distilleries\FormBuilder\FormValidator |
|
7
|
|
|
{ |
|
8
|
|
|
|
|
9
|
|
|
public static $rules = [ |
|
10
|
|
|
'libelle' => 'required' |
|
11
|
|
|
]; |
|
12
|
|
|
public static $rules_update = null; |
|
13
|
|
|
|
|
14
|
6 |
|
public function buildForm() |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
$this |
|
18
|
6 |
|
->add('libelle', 'text', [ |
|
19
|
6 |
|
'validation' => 'required', |
|
20
|
6 |
|
'label' => trans('expendable::form.name'), |
|
21
|
6 |
|
'help' => trans('expendable::form.auto_sufix') |
|
22
|
|
|
]) |
|
23
|
6 |
|
->add('state', 'choice', [ |
|
24
|
6 |
|
'choices' => StaticLabel::states(), |
|
25
|
6 |
|
'empty_value' => '-', |
|
26
|
6 |
|
'label' => trans('expendable::form.state'), |
|
27
|
|
|
'expanded' => true, |
|
28
|
|
|
'multiple' => true |
|
29
|
|
|
]) |
|
30
|
6 |
|
->add('models', 'choice', [ |
|
31
|
6 |
|
'choices' => $this->getChoiceModels(), |
|
32
|
6 |
|
'empty_value' => '-', |
|
33
|
6 |
|
'label' => trans('expendable::form.model') |
|
34
|
|
|
]) |
|
35
|
6 |
|
->add('colon_datatable', 'tag', [ |
|
36
|
6 |
|
'label' => trans('expendable::form.columns'), |
|
37
|
6 |
|
'help' => trans('expendable::form.help_colon_datatable') |
|
38
|
|
|
]) |
|
39
|
6 |
|
->add('fields_form', 'tag', [ |
|
40
|
6 |
|
'label' => trans('expendable::form.fields'), |
|
41
|
6 |
|
'help' => trans('expendable::form.help_fields_form') |
|
42
|
|
|
]) |
|
43
|
6 |
|
->addDefaultActions(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
6 |
|
protected function getChoiceModels() |
|
47
|
|
|
{ |
|
48
|
|
|
$allModels = [ |
|
49
|
|
|
[ |
|
50
|
6 |
|
'path' => app_path().DIRECTORY_SEPARATOR, |
|
51
|
6 |
|
'namespace' => '{{app}}', |
|
52
|
|
|
], |
|
53
|
|
|
[ |
|
54
|
6 |
|
'path' => app_path().DIRECTORY_SEPARATOR.'Models'.DIRECTORY_SEPARATOR, |
|
55
|
6 |
|
'namespace' => '{{app}}Models\\', |
|
56
|
|
|
], |
|
57
|
|
|
[ |
|
58
|
6 |
|
'path' => __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Models'.DIRECTORY_SEPARATOR, |
|
59
|
6 |
|
'namespace' => 'Distilleries\\Expendable\\Models\\', |
|
60
|
|
|
], |
|
61
|
|
|
]; |
|
62
|
|
|
|
|
63
|
6 |
|
$choices = []; |
|
64
|
6 |
|
foreach ($allModels as $config) { |
|
65
|
6 |
|
if (app('files')->isDirectory($config['path'])) { |
|
66
|
6 |
|
$models = app('files')->files($config['path']); |
|
67
|
6 |
|
foreach ($models as $model) { |
|
68
|
6 |
|
$choice = explode('/', $model); |
|
69
|
6 |
|
$model = preg_replace('/.php/i', '', last($choice)); |
|
70
|
6 |
|
$choices[$config['namespace'].$model] = $model; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
6 |
|
return $choices; |
|
77
|
|
|
} |
|
78
|
|
|
} |