-
Notifications
You must be signed in to change notification settings - Fork 554
/
Files.php
81 lines (64 loc) · 1.85 KB
/
Files.php
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
<?php
namespace A17\Twill\Services\Forms\Fields;
use A17\Twill\Services\Forms\Fields\Traits\CanHaveButtonOnTop;
use A17\Twill\Services\Forms\Fields\Traits\HasFieldNote;
use A17\Twill\Services\Forms\Fields\Traits\HasMax;
use A17\Twill\Services\Forms\Fields\Traits\IsTranslatable;
use Illuminate\Support\Str;
class Files extends BaseFormField
{
use IsTranslatable;
use HasMax;
use HasFieldNote;
use CanHaveButtonOnTop;
protected ?string $itemLabel = null;
protected ?int $filesizeMax = 0;
public static function make(): static
{
$instance = new self(
component: \A17\Twill\View\Components\Fields\Files::class,
mandatoryProperties: ['name', 'label']
);
// Max needs to be 1 by default for this component.
// Cannot be null.
$instance->max = 1;
return $instance;
}
/**
* {@inheritDoc}
*/
public function label(string $label): static
{
if (!$this->itemLabel) {
$this->itemLabel = strtolower($label);
}
return parent::label($label);
}
/**
* Default is 0 which is unlimited (depending on server config).
*/
public function filesizeMax(int $filesizeMax): static
{
$this->filesizeMax = $filesizeMax;
return $this;
}
/**
* The label to display for items, defaults to the field label.
*/
public function itemLabel(string $itemLabel): static
{
$this->itemLabel = $itemLabel;
return $this;
}
public function getNote(): string
{
if ($this->note) {
return $this->note;
}
// @todo: Add new translatable string for this.
if ($this->max > 1) {
return "Add up to {$this->max} {$this->itemLabel}";
}
return 'Add one ' . Str::singular($this->itemLabel);
}
}