1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SleepingOwl\Admin\Display\Column\Editable; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
6
|
|
|
use SleepingOwl\Admin\Display\Column\NamedColumn; |
7
|
|
|
|
8
|
|
|
class EditableColumn extends NamedColumn |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var string |
12
|
|
|
*/ |
13
|
|
|
protected $url = null; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $title = null; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $editableMode = 'popup'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Text constructor. |
27
|
|
|
* |
28
|
|
|
* @param $name |
29
|
|
|
* @param $label |
30
|
|
|
*/ |
31
|
|
|
public function __construct($name, $label = null) |
32
|
|
|
{ |
33
|
|
|
parent::__construct($name, $label); |
34
|
|
|
|
35
|
|
|
$this->clearHtmlAttributes(); |
36
|
|
|
|
37
|
|
|
$this->setHtmlAttributes([ |
38
|
|
|
'class' => 'inline-editable', |
39
|
|
|
]); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param bool $sortable |
|
|
|
|
44
|
|
|
* |
45
|
|
|
* @return $this |
46
|
|
|
*/ |
47
|
|
|
public function getTitle() |
48
|
|
|
{ |
49
|
|
|
if (isset($this->title)) { |
50
|
|
|
return $this->title; |
51
|
|
|
} else { |
52
|
|
|
return $this->header->getTitle(); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param bool $sortable |
|
|
|
|
58
|
|
|
* |
59
|
|
|
* @return $this |
60
|
|
|
*/ |
61
|
|
|
public function setTitle($title) |
62
|
|
|
{ |
63
|
|
|
$this->title = $title; |
64
|
|
|
|
65
|
|
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
public function getUrl() |
72
|
|
|
{ |
73
|
|
|
if (! $this->url) { |
74
|
|
|
return request()->url(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return $this->url; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param $url |
82
|
|
|
* @return string |
83
|
|
|
*/ |
84
|
|
|
public function setUrl($url) |
85
|
|
|
{ |
86
|
|
|
$this->url = $url; |
87
|
|
|
|
88
|
|
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return string |
93
|
|
|
*/ |
94
|
|
|
public function getEditableMode() |
95
|
|
|
{ |
96
|
|
|
return $this->editableMode; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param $url |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
|
|
public function setEditableMode($mode) |
104
|
|
|
{ |
105
|
|
|
if (isset($mode) && in_array($mode, ['inline', 'popup'])) { |
106
|
|
|
$this->editableMode = $mode; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
return $this; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return array |
114
|
|
|
*/ |
115
|
|
|
public function toArray() |
116
|
|
|
{ |
117
|
|
|
return parent::toArray() + [ |
118
|
|
|
'id' => $this->getModel()->getKey(), |
119
|
|
|
'value' => $this->getModelValue(), |
120
|
|
|
'isEditable' => $this->getModelConfiguration()->isEditable($this->getModel()), |
121
|
|
|
'url' => $this->getUrl(), |
122
|
|
|
'title' => $this->getTitle(), |
123
|
|
|
'mode' => $this->getEditableMode(), |
124
|
|
|
]; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.