-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSection.php
More file actions
120 lines (99 loc) · 2.55 KB
/
Copy pathSection.php
File metadata and controls
120 lines (99 loc) · 2.55 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
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
namespace ADT\Forms;
use Exception;
use Nette\Forms\Container;
use Nette\Forms\Control;
use Nette\Forms\ControlGroup;
use Nette\Forms\SubmitterControl;
use Nette\InvalidArgumentException;
class Section extends ControlGroup
{
use ElementsTrait;
protected ?string $name = null;
/** @var Section[] */
protected array $ancestorSections;
protected Container $parent;
protected array|SubmitterControl $watchForRedraw;
protected array $validationScope = [];
public function __construct(Container $parent, array $ancestorSections, ?string $name)
{
parent::__construct();
$this->parent = $parent;
$this->ancestorSections = $ancestorSections;
$this->name = $name;
}
public function addSection(Container $parent, array $ancestorSections, ?string $name): Section
{
$this->sections[] = $section = new Section($parent, $ancestorSections, $name);
return $section;
}
public function getName(): ?string
{
return $this->name;
}
public function getParent(): Container
{
return $this->parent;
}
/**
* @throws Exception
*/
public function getHtmlId(): string
{
if ($this->name === null) {
throw new Exception('Section name is not set.');
}
if ($this->parent instanceof Form) {
return $this->name;
}
return $this->parent->lookupPath(Form::class) . Form::GROUP_LEVEL_SEPARATOR . $this->name;
}
public function add(...$items): static
{
foreach ($items as $item) {
if ($item instanceof Control) {
$item->setOption('section', $this);
$this->controls[$item] = null;
} elseif ($item instanceof Container) {
if ($item->getParent() instanceof DynamicContainer) {
continue;
}
$this->controls[$item] = null;
} else {
$type = get_debug_type($item);
throw new InvalidArgumentException("Control or Container items expected, $type given.");
}
}
return $this;
}
public function getComponents(): array
{
$components = [];
foreach ($this->getControls() as $control) {
$components[$control->getName()] = $control;
}
return $components;
}
public function getAncestorSections(): array
{
return $this->ancestorSections;
}
public function getWatchForRedraw(): array|SubmitterControl
{
return $this->watchForRedraw;
}
public function setWatchForRedraw(array|SubmitterControl $watchForRedraw): static
{
$this->watchForRedraw = $watchForRedraw;
return $this;
}
public function getValidationScope(): array
{
return $this->validationScope;
}
public function setValidationScope(array $validationScope): static
{
$this->validationScope = $validationScope;
return $this;
}
}