1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Encore\Admin\Form\Field; |
4
|
|
|
|
5
|
|
|
use Encore\Admin\Admin; |
6
|
|
|
use Illuminate\Support\Arr; |
7
|
|
|
|
8
|
|
|
trait HasValuePicker |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var ValuePicker |
12
|
|
|
*/ |
13
|
|
|
protected $picker; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $btn = ''; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @param string $picker |
22
|
|
|
* @param string $column |
23
|
|
|
* @return $this |
24
|
|
|
*/ |
25
|
|
|
public function pick($picker, $column = '') |
26
|
|
|
{ |
27
|
|
|
$this->picker = new ValuePicker($picker, $column); |
28
|
|
|
|
29
|
|
|
return $this; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param string $picker |
34
|
|
|
* @param string $column |
35
|
|
|
* @param string $delimiter |
36
|
|
|
*/ |
37
|
|
|
public function pickMultiple($picker, $column = '', $delimiter = ',') |
38
|
|
|
{ |
39
|
|
|
$this->picker = new ValuePicker($picker, $column, true, $delimiter); |
40
|
|
|
|
41
|
|
|
return $this; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return void |
46
|
|
|
*/ |
47
|
|
|
protected function mountPicker() |
48
|
|
|
{ |
49
|
|
|
if ($this->picker) { |
50
|
|
|
$this->picker->mount($this); |
51
|
|
|
$this->addVariables(['btn' => $this->btn]); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
|
|
protected function getRules() |
59
|
|
|
{ |
60
|
|
|
$rules = parent::getRules(); |
61
|
|
|
|
62
|
|
|
array_delete($rules, 'image'); |
63
|
|
|
|
64
|
|
|
return $rules; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string |
69
|
|
|
*/ |
70
|
|
|
protected function renderFilePicker() |
71
|
|
|
{ |
72
|
|
|
$this->view = 'admin::form.filepicker'; |
|
|
|
|
73
|
|
|
|
74
|
|
|
$this->picker->mount($this); |
75
|
|
|
|
76
|
|
|
$this->attribute('type', 'text') |
|
|
|
|
77
|
|
|
->attribute('id', $this->id) |
|
|
|
|
78
|
|
|
->attribute('name', $this->elementName ?: $this->formatName($this->column)) |
|
|
|
|
79
|
|
|
->attribute('value', old($this->elementName ?: $this->column, $this->value())) |
|
|
|
|
80
|
|
|
->attribute('class', 'form-control '.$this->getElementClassString()) |
|
|
|
|
81
|
|
|
->attribute('placeholder', $this->getPlaceholder()); |
|
|
|
|
82
|
|
|
|
83
|
|
|
$this->addVariables([ |
|
|
|
|
84
|
|
|
'preview' => $this->picker->preview(), |
85
|
|
|
'btn' => $this->btn |
86
|
|
|
]); |
87
|
|
|
|
88
|
|
|
return parent::render(); |
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param string $wrap |
|
|
|
|
93
|
|
|
*/ |
94
|
|
|
public function addPickBtn($btn) |
95
|
|
|
{ |
96
|
|
|
$this->btn = $btn; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
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
Idable
provides a methodequalsId
that 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.