-
Notifications
You must be signed in to change notification settings - Fork 586
/
Copy pathMedias.php
149 lines (113 loc) · 3.24 KB
/
Medias.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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?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;
class Medias extends BaseFormField
{
use IsTranslatable;
use HasMax;
use HasFieldNote;
use CanHaveButtonOnTop;
protected bool $withAddInfo = true;
protected bool $withVideoUrl = true;
protected bool $withCaption = true;
protected ?int $altTextMaxLength = null;
protected ?int $captionMaxLength = null;
protected array $extraMetadatas = [];
protected int $widthMin = 0;
protected int $heightMin = 0;
protected bool $activeCrop = true;
protected bool $disableTranslate = false;
public static function make(): static
{
$instance = new self(
component: \A17\Twill\View\Components\Fields\Medias::class,
mandatoryProperties: ['name', 'label']
);
// Max needs to be 1 by default for this component.
// Cannot be null.
$instance->max = 1;
return $instance;
}
/**
* Disables the additional metadata input fields.
*/
public function withoutAddInfo(bool $withoutAddInfo = true): static
{
$this->withAddInfo = !$withoutAddInfo;
return $this;
}
/**
* Removes the video url field from the additional info section.
*/
public function withoutVideoUrl(bool $withoutVideoUrl = true): static
{
$this->withVideoUrl = !$withoutVideoUrl;
return $this;
}
/**
* Removes the caption field from the additional info section.
*/
public function withoutCaption(bool $withoutCaption = true): static
{
$this->withCaption = !$withoutCaption;
return $this;
}
/**
* Set the max length of the alt field.
*/
public function altTextMaxLength(bool $altTextMaxLength): static
{
$this->altTextMaxLength = $altTextMaxLength;
return $this;
}
/**
* Set the max length of the caption field.
*/
public function captionMaxLength(int $captionMaxLength): static
{
$this->captionMaxLength = $captionMaxLength;
return $this;
}
/**
* Define custom extra metadata.
*
* @see https://twillcms.com/docs/form-fields/medias.html#content-extra-metadatas
*/
public function extraMetadatas(array $extraMetadatas): static
{
$this->extraMetadatas = $extraMetadatas;
return $this;
}
/**
* The minimum width of the image.
*/
public function minWidth(int $minWidth): static
{
$this->widthMin = $minWidth;
return $this;
}
/**
* The minimum height of the image.
*/
public function minHeight(int $minHeight): static
{
$this->heightMin = $minHeight;
return $this;
}
/**
* Hide the cropper.
*/
public function hideActiveCrop(bool $hideActiveCrop = true): static
{
$this->activeCrop = !$hideActiveCrop;
return $this;
}
public function disableTranslate(): static
{
$this->disableTranslate = true;
return $this;
}
}