-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStaticContainer.php
More file actions
88 lines (67 loc) · 1.83 KB
/
Copy pathStaticContainer.php
File metadata and controls
88 lines (67 loc) · 1.83 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
<?php
namespace ADT\Forms;
use Closure;
use Nette\Application\UI\Presenter;
use Nette\Forms\Controls\BaseControl;
use Nette\Http\FileUpload;
class StaticContainer extends BaseContainer
{
use GetComponentTrait;
use SectionTrait;
use ElementsTrait;
private ?BaseControl $isFilledComponent = null;
private bool $isTemplate = false;
public function __construct(string $entityFieldName, Closure $factory, ?string $isFilledComponentName)
{
$this->monitor(Presenter::class, function() use ($entityFieldName, $factory, $isFilledComponentName) {
$factory($this);
if ($isFilledComponentName) {
$this->setIsFilledComponent($this->addText($isFilledComponentName)->setHtmlAttribute('style', 'display: none'));
}
});
}
public function validate(?array $controls = NULL): void
{
parent::validate($controls);
if (
$this->isRequired()
&&
$this->isEmpty()
) {
$this->addError($this->getRequiredMessage());
}
}
public function getIsFilledComponent(): ?BaseControl
{
return $this->isFilledComponent;
}
public function setIsFilledComponent(BaseControl $isFilledComponent): self
{
$this->isFilledComponent = $isFilledComponent;
return $this;
}
public function isEmpty(bool $excludeIsFilledComponent = false): bool
{
// we don't want to validate the controls, just check if they are empty, or not
// getValues causes a loop
$values = $this->getUntrustedValues('array');
if ($excludeIsFilledComponent) {
unset($values[$this->getIsFilledComponent()->getName()]);
}
foreach ($values as &$_value) {
if ($_value instanceof FileUpload && !$_value->isOk()) {
$_value = null;
}
}
return !array_filter($values);
}
public function isTemplate(): bool
{
return $this->isTemplate;
}
public function setIsTemplate(bool $isTemplate): self
{
$this->isTemplate = $isTemplate;
return $this;
}
}