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