1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yaro\Jarboe\Table\Fields; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
6
|
|
|
use Yaro\Jarboe\Table\CRUD; |
7
|
|
|
use Yaro\Jarboe\Table\Fields\Interfaces\FieldPropsInterface; |
8
|
|
|
use Yaro\Jarboe\Table\Fields\Traits\Column; |
9
|
|
|
use Yaro\Jarboe\Table\Fields\Traits\DefaultTrait; |
10
|
|
|
use Yaro\Jarboe\Table\Fields\Traits\Errors; |
11
|
|
|
use Yaro\Jarboe\Table\Fields\Traits\Filter; |
12
|
|
|
use Yaro\Jarboe\Table\Fields\Traits\Hidden; |
|
|
|
|
13
|
|
|
use Yaro\Jarboe\Table\Fields\Traits\Model; |
14
|
|
|
use Yaro\Jarboe\Table\Fields\Traits\Name; |
15
|
|
|
use Yaro\Jarboe\Table\Fields\Traits\OldAndAttribute; |
16
|
|
|
use Yaro\Jarboe\Table\Fields\Traits\Readonly; |
17
|
|
|
use Yaro\Jarboe\Table\Fields\Traits\Tab; |
18
|
|
|
use Yaro\Jarboe\Table\Fields\Traits\Title; |
19
|
|
|
use Yaro\Jarboe\Table\Fields\Traits\Width; |
20
|
|
|
|
21
|
|
|
abstract class AbstractField implements FieldPropsInterface |
22
|
|
|
{ |
23
|
|
|
use Hidden; |
24
|
|
|
use Width; |
25
|
|
|
use Column; |
26
|
|
|
use Tab; |
27
|
|
|
use Readonly; |
28
|
|
|
use DefaultTrait; |
29
|
|
|
use Title; |
30
|
|
|
use Name; |
31
|
|
|
use OldAndAttribute; |
32
|
|
|
use Model; |
33
|
|
|
use Filter; |
34
|
|
|
use Errors; |
35
|
|
|
|
36
|
|
|
const DEFAULT_TAB_IDENT = '[extra]'; |
37
|
|
|
|
38
|
|
|
private $crud; |
39
|
1002 |
|
public static $repeaterAdapterClass; |
40
|
|
|
|
41
|
1002 |
|
public static function make($name = '', $title = '') |
42
|
|
|
{ |
43
|
1002 |
|
$field = new static; |
44
|
951 |
|
|
45
|
|
|
if (!$title) { |
46
|
1002 |
|
$title = preg_replace('~_~', ' ', ucfirst($name)); |
47
|
1002 |
|
} |
48
|
1002 |
|
$field->title($title); |
49
|
|
|
$field->name($name); |
50
|
1002 |
|
$field->tab(self::DEFAULT_TAB_IDENT); |
51
|
|
|
|
52
|
|
|
return $field; |
53
|
19 |
|
} |
54
|
|
|
|
55
|
19 |
|
public function value(Request $request) |
56
|
19 |
|
{ |
57
|
3 |
|
$value = $request->get($this->name()); |
58
|
|
|
if (!$value && $this->isNullable()) { |
59
|
|
|
return null; |
60
|
19 |
|
} |
61
|
|
|
|
62
|
|
|
return $value; |
63
|
14 |
|
} |
64
|
|
|
|
65
|
14 |
|
public function shouldSkip(Request $request) |
66
|
|
|
{ |
67
|
|
|
return false; |
68
|
1 |
|
} |
69
|
|
|
|
70
|
|
|
public function afterStore($model, Request $request) |
71
|
1 |
|
{ |
72
|
|
|
// dummy |
73
|
2 |
|
} |
74
|
|
|
|
75
|
|
|
public function afterUpdate($model, Request $request) |
76
|
2 |
|
{ |
77
|
|
|
// dummy |
78
|
1 |
|
} |
79
|
|
|
|
80
|
|
|
public function beforeUpdate($model) |
81
|
1 |
|
{ |
82
|
|
|
// dummy |
83
|
12 |
|
} |
84
|
|
|
|
85
|
12 |
|
public function isInline() |
86
|
|
|
{ |
87
|
|
|
return false; |
88
|
19 |
|
} |
89
|
|
|
|
90
|
19 |
|
public function isRelationField() |
91
|
|
|
{ |
92
|
|
|
return false; |
93
|
16 |
|
} |
94
|
|
|
|
95
|
16 |
|
public function isMultiple() |
96
|
|
|
{ |
97
|
|
|
return false; |
98
|
17 |
|
} |
99
|
|
|
|
100
|
17 |
|
public function isEncode() |
101
|
|
|
{ |
102
|
|
|
return false; |
103
|
74 |
|
} |
104
|
|
|
|
105
|
74 |
|
public function isMarkupRow() |
106
|
|
|
{ |
107
|
|
|
return false; |
108
|
4 |
|
} |
109
|
|
|
|
110
|
4 |
|
public function isOrderable() |
111
|
|
|
{ |
112
|
|
|
return false; |
113
|
17 |
|
} |
114
|
|
|
|
115
|
17 |
|
public function isAjax() |
116
|
|
|
{ |
117
|
|
|
return false; |
118
|
3 |
|
} |
119
|
|
|
|
120
|
3 |
|
public function isNullable() |
121
|
|
|
{ |
122
|
|
|
return false; |
123
|
13 |
|
} |
124
|
|
|
|
125
|
13 |
|
public function hasTooltip() |
126
|
|
|
{ |
127
|
|
|
return false; |
128
|
14 |
|
} |
129
|
|
|
|
130
|
14 |
|
public function hasClipboardButton() |
131
|
|
|
{ |
132
|
|
|
return false; |
133
|
70 |
|
} |
134
|
|
|
|
135
|
70 |
|
public function isTranslatable() |
136
|
|
|
{ |
137
|
|
|
return false; |
138
|
16 |
|
} |
139
|
|
|
|
140
|
16 |
|
public function isMaskable() |
141
|
|
|
{ |
142
|
|
|
return false; |
143
|
8 |
|
} |
144
|
|
|
|
145
|
8 |
|
public function getPlaceholder() |
146
|
|
|
{ |
147
|
|
|
return null; |
148
|
15 |
|
} |
149
|
|
|
|
150
|
15 |
|
public function hasMaxlength(): bool |
151
|
|
|
{ |
152
|
|
|
return false; |
153
|
1 |
|
} |
154
|
|
|
|
155
|
1 |
|
public function getHistoryView($value) |
156
|
1 |
|
{ |
157
|
|
|
return view('jarboe::crud.fields.abstract.history', [ |
158
|
|
|
'value' => $value, |
159
|
|
|
]); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
abstract public function getListView($model); |
|
|
|
|
163
|
|
|
|
164
|
|
|
abstract public function getEditFormView($model); |
|
|
|
|
165
|
|
|
|
166
|
|
|
abstract public function getCreateFormView(); |
|
|
|
|
167
|
58 |
|
|
168
|
|
|
// TODO: interface type-hinting |
169
|
58 |
|
public function prepare(CRUD $crud) |
170
|
|
|
{ |
171
|
58 |
|
$this->crud = $crud; |
172
|
|
|
|
173
|
|
|
if ($this->filter()) { |
174
|
|
|
$this->filter()->value( |
175
|
|
|
$this->filter()->getValue($crud->tableIdentifier()) |
176
|
|
|
); |
177
|
58 |
|
} |
178
|
|
|
|
179
|
58 |
|
$this->setModel($crud->getModel()); |
180
|
|
|
|
181
|
|
|
if (method_exists($this, 'setRelationSearchUrl')) { |
182
|
58 |
|
$this->setRelationSearchUrl($crud->relationSearchUrl()); |
|
|
|
|
183
|
58 |
|
} |
184
|
|
|
if (method_exists($this, 'setInlineUrl')) { |
185
|
58 |
|
$this->setInlineUrl($crud->inlineUrl()); |
|
|
|
|
186
|
|
|
} |
187
|
|
|
if ($this->isTranslatable()) { |
188
|
|
|
$this->locales($crud->getLocales()); |
|
|
|
|
189
|
58 |
|
$this->setCurrentLocale($crud->getCurrentLocale()); |
|
|
|
|
190
|
|
|
} |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
protected function crud(): CRUD |
194
|
|
|
{ |
195
|
|
|
return $this->crud; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
public function belongsToArray(): bool |
199
|
|
|
{ |
200
|
|
|
return false; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
public function getAncestorName(): string |
204
|
|
|
{ |
205
|
|
|
throw new \RuntimeException('Not available: must be inherited from BelongsToArray trait.'); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
public function getDescendantName(): string |
209
|
|
|
{ |
210
|
|
|
throw new \RuntimeException('Not available: must be inherited from BelongsToArray trait.'); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
public function getDotPatternName(): string |
214
|
|
|
{ |
215
|
|
|
throw new \RuntimeException('Not available: must be inherited from BelongsToArray trait.'); |
216
|
|
|
} |
217
|
|
|
} |
218
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: