1
|
|
|
<?php namespace Distilleries\FormBuilder;
|
2
|
|
|
|
3
|
|
|
use Kris\LaravelFormBuilder\Form;
|
4
|
|
|
|
5
|
|
|
class FormView extends Form {
|
6
|
|
|
|
7
|
|
|
|
8
|
|
|
// ------------------------------------------------------------------------------------------------
|
9
|
|
|
// ------------------------------------------------------------------------------------------------
|
10
|
|
|
// ------------------------------------------------------------------------------------------------
|
11
|
|
|
|
12
|
140 |
|
public function add($name, $type = 'text', array $options = [], $modify = false, $noOveride = false)
|
13
|
|
|
{
|
14
|
|
|
|
15
|
|
|
|
16
|
140 |
|
if (!isset($options['noInEditView']))
|
17
|
140 |
|
{
|
18
|
132 |
|
$options['noInEditView'] = false;
|
19
|
132 |
|
}
|
20
|
|
|
|
21
|
|
|
|
22
|
140 |
|
if (!empty($this->formOptions) && !empty($this->formOptions['do_not_display_'.$name]) && $this->formOptions['do_not_display_'.$name] === true)
|
23
|
140 |
|
{
|
24
|
4 |
|
$type = 'hidden';
|
25
|
|
|
|
26
|
4 |
|
if (!empty($options) && !empty($options['selected']))
|
27
|
4 |
|
{
|
28
|
4 |
|
$options['default_value'] = $options['selected'];
|
29
|
4 |
|
}
|
30
|
|
|
|
31
|
4 |
|
}
|
32
|
|
|
|
33
|
140 |
|
if ($type == 'choice' && !isset($options['selected']))
|
34
|
140 |
|
{
|
35
|
36 |
|
if (isset($this->model->{$name}))
|
36
|
36 |
|
{
|
37
|
4 |
|
$options['selected'] = $this->model->{$name};
|
38
|
4 |
|
}
|
39
|
36 |
|
}
|
40
|
|
|
|
41
|
140 |
|
return parent::add($name, $type, $options, $modify);
|
42
|
|
|
}
|
43
|
|
|
|
44
|
|
|
// ------------------------------------------------------------------------------------------------
|
45
|
|
|
// ------------------------------------------------------------------------------------------------
|
46
|
|
|
// ------------------------------------------------------------------------------------------------
|
47
|
|
|
|
48
|
76 |
|
public function renderFormView(array $options = [])
|
49
|
|
|
{
|
50
|
76 |
|
return $this->view($options, $this->fields);
|
51
|
|
|
}
|
52
|
|
|
|
53
|
|
|
// ------------------------------------------------------------------------------------------------
|
54
|
|
|
|
55
|
|
|
|
56
|
4 |
|
public function renderRestView()
|
57
|
|
|
{
|
58
|
4 |
|
$fields = $this->getUnrenderedFields();
|
59
|
|
|
|
60
|
4 |
|
return $this->view([], $fields);
|
61
|
|
|
}
|
62
|
|
|
|
63
|
|
|
// ------------------------------------------------------------------------------------------------
|
64
|
|
|
|
65
|
80 |
|
protected function view($options, $fields)
|
66
|
|
|
{
|
67
|
80 |
|
$formOptions = $this->formHelper->mergeOptions($this->formOptions, $options);
|
68
|
|
|
|
69
|
80 |
|
return $this->formHelper->getView()
|
70
|
80 |
|
->make($this->formHelper->getConfig('form'))
|
71
|
80 |
|
->with(['showFields' => true])
|
72
|
80 |
|
->with(['showEnd' => false])
|
73
|
80 |
|
->with(['showStart' => false])
|
74
|
80 |
|
->with(['isNotEditable' => true])
|
75
|
80 |
|
->with('formOptions', $formOptions)
|
76
|
80 |
|
->with('fields', $fields)
|
77
|
80 |
|
->with('model', $this->getModel())
|
78
|
80 |
|
->render();
|
79
|
|
|
}
|
80
|
|
|
} |