-
-
Notifications
You must be signed in to change notification settings - Fork 243
Expand file tree
/
Copy pathFieldSet.php
More file actions
107 lines (91 loc) · 2.3 KB
/
Copy pathFieldSet.php
File metadata and controls
107 lines (91 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
namespace Backend\FormWidgets;
use ApplicationException;
use Backend\Classes\FormField;
use Backend\Classes\FormWidgetBase;
use Backend\Widgets\Form;
/**
* FieldSet
* Renders a fieldset from multiple form fields.
*
* @package winter\wn-backend-module
* @author Marc Jauvin <marc.jauvin@gmail.com>
*/
class FieldSet extends FormWidgetBase
{
/**
* @inheritDoc
*/
protected $defaultAlias = 'fieldset';
/**
* @var array Form configuration
*/
public $form;
/**
* @var bool Determines if this form field should display comments and labels.
*/
public $showLabels = false;
/**
* @var Form form widget reference
*/
protected $formWidget;
/**
* @inheritDoc
*/
public function init()
{
$this->fillFromConfig([
'fields',
]);
if ($this->formField->disabled) {
$this->previewMode = true;
}
$config = $this->makeConfig(['fields' => $this->fields]);
$config->model = $this->model;
$config->data = $this->getLoadValue();
$config->alias = $this->alias . $this->defaultAlias;
// set arrayName from parent form to save fields to the model
$config->arrayName = $this->getParentForm()->arrayName;
$config->isNested = true;
$widget = $this->formWidget = $this->makeWidget(Form::class, $config);
$widget->previewMode = $this->previewMode;
$widget->bindToController();
}
protected function loadAssets()
{
$this->addCss('css/fieldset.css', 'core');
}
/**
* return the internal formwidget's fields
*/
public function getFormFields(): array
{
return $this->formWidget->getFields();
}
/**
* return an internal formwidget's formWidget
*/
public function getFormWidget($field): FormWidgetBase
{
return $this->formWidget->getFormWidget($field);
}
/**
* @inheritdoc
*/
public function render()
{
$this->prepareVars();
return $this->makePartial('fieldset');
}
public function prepareVars()
{
$this->formWidget->previewMode = $this->previewMode;
}
/**
* @inheritDoc
*/
public function getSaveValue($value)
{
return FormField::NO_SAVE_DATA;
}
}