|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Encore\Admin\Form\Field; |
|
4
|
|
|
|
|
5
|
|
|
use Encore\Admin\Admin; |
|
6
|
|
|
use Encore\Admin\Form\Field; |
|
7
|
|
|
use Illuminate\Support\Arr; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @mixin Field |
|
11
|
|
|
*/ |
|
12
|
|
|
trait HasValuePicker |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var ValuePicker |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $picker; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @param string $picker |
|
21
|
|
|
* @param string $column |
|
22
|
|
|
* @return $this |
|
23
|
|
|
*/ |
|
24
|
|
|
public function pick($picker, $column = '') |
|
25
|
|
|
{ |
|
26
|
|
|
$this->picker = new ValuePicker($picker, $column); |
|
27
|
|
|
|
|
28
|
|
|
return $this; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param string $picker |
|
33
|
|
|
* @param string $column |
|
34
|
|
|
* @param string $separator |
|
35
|
|
|
*/ |
|
36
|
|
|
public function pickMany($picker, $column = '', $separator = ';') |
|
37
|
|
|
{ |
|
38
|
|
|
$this->picker = new ValuePicker($picker, $column, true, $separator); |
|
39
|
|
|
|
|
40
|
|
|
return $this; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param \Closure|null $callback |
|
45
|
|
|
* @return $this |
|
46
|
|
|
*/ |
|
47
|
|
|
protected function mountPicker(\Closure $callback = null) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->picker && $this->picker->mount($this, $callback); |
|
50
|
|
|
|
|
51
|
|
|
return $this; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @return string |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function getRules() |
|
58
|
|
|
{ |
|
59
|
|
|
$rules = parent::getRules(); |
|
60
|
|
|
|
|
61
|
|
|
array_delete($rules, 'image'); |
|
62
|
|
|
|
|
63
|
|
|
return $rules; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string |
|
68
|
|
|
*/ |
|
69
|
|
|
protected function renderFilePicker() |
|
70
|
|
|
{ |
|
71
|
|
|
$this->mountPicker() |
|
|
|
|
|
|
72
|
|
|
->setView('admin::form.filepicker') |
|
73
|
|
|
->attribute('type', 'text') |
|
74
|
|
|
->attribute('id', $this->id) |
|
|
|
|
|
|
75
|
|
|
->attribute('name', $this->elementName ?: $this->formatName($this->column)) |
|
|
|
|
|
|
76
|
|
|
->attribute('value', old($this->elementName ?: $this->column, $this->value())) |
|
|
|
|
|
|
77
|
|
|
->attribute('class', 'form-control '.$this->getElementClassString()) |
|
|
|
|
|
|
78
|
|
|
->attribute('placeholder', $this->getPlaceholder()) |
|
|
|
|
|
|
79
|
|
|
->addVariables([ |
|
80
|
|
|
'preview' => $this->picker->getPreview(get_called_class()), |
|
81
|
|
|
]); |
|
82
|
|
|
|
|
83
|
|
|
return Admin::component('admin::form.filepicker', $this->variables()); |
|
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.