1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hechoenlaravel\JarvisFoundation\Field\Text; |
4
|
|
|
|
5
|
|
|
use Styde\Html\Facades\Field; |
6
|
|
|
use Hechoenlaravel\JarvisFoundation\Field\FieldTypeInterface; |
7
|
|
|
use Hechoenlaravel\JarvisFoundation\Field\FieldTypeImplementationTrait; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class TextFieldType |
11
|
|
|
* @package Hechoenlaravel\JarvisFoundation\Field\Text |
12
|
|
|
*/ |
13
|
|
|
class TextFieldType implements FieldTypeInterface |
14
|
|
|
{ |
15
|
|
|
use FieldTypeImplementationTrait; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var |
19
|
|
|
*/ |
20
|
|
|
private $value; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $columnType = "string"; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* The field type name |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
public $name = "Texto"; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* The field slug for the instance |
35
|
|
|
* @var |
36
|
|
|
*/ |
37
|
|
|
public $fieldSlug; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* The field Name for the instance |
41
|
|
|
* @var |
42
|
|
|
*/ |
43
|
|
|
public $fieldName; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* The field description for the instance |
47
|
|
|
* @var |
48
|
|
|
*/ |
49
|
|
|
public $fieldDescription; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* The field Options for the Instance |
53
|
|
|
* @var |
54
|
|
|
*/ |
55
|
|
|
public $fieldOptions; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Validation rules for the field type |
59
|
|
|
* @var array |
60
|
|
|
*/ |
61
|
|
|
public $validationRules = ['string']; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* get the column type for this field type |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
|
|
public function getColumnType() |
68
|
|
|
{ |
69
|
|
|
return $this->columnType; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Set a value for this field; |
74
|
|
|
* @param $value |
75
|
|
|
*/ |
76
|
|
|
public function setValue($value) |
77
|
|
|
{ |
78
|
|
|
$this->value = $value; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* get the value for the field |
84
|
|
|
* @return mixed |
85
|
|
|
*/ |
86
|
|
|
public function getValue() |
87
|
|
|
{ |
88
|
|
|
return $this->value; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* return the form view |
93
|
|
|
* @return mixed |
94
|
|
|
*/ |
95
|
|
|
public function present() |
96
|
|
|
{ |
97
|
|
|
return Field::text($this->fieldSlug, $this->value, ['label' => $this->fieldName]); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Que the form for the options of the field type |
102
|
|
|
* @return mixed |
103
|
|
|
*/ |
104
|
|
|
public function getOptionsForm() |
105
|
|
|
{ |
106
|
|
|
return view('jarvisPlatform::field.types.text.optionsForm')->render(); |
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Take the value and capitalize the first letter. |
111
|
|
|
* @param $value |
112
|
|
|
* @return string |
113
|
|
|
*/ |
114
|
|
|
public function preSaveEvent($value) |
115
|
|
|
{ |
116
|
|
|
return mb_strtolower($value); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return mixed |
121
|
|
|
*/ |
122
|
|
|
public function presentFront() |
123
|
|
|
{ |
124
|
|
|
$options = unserialize($this->fieldOptions); |
125
|
|
|
foreach($options as $option) { |
126
|
|
|
if(array_key_exists('transform', $option)) { |
127
|
|
|
return $this->transformText($option['transform']); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
return strtoupper($this->value); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @param $transformation |
135
|
|
|
* @return string |
136
|
|
|
*/ |
137
|
|
|
protected function transformText($transformation) |
138
|
|
|
{ |
139
|
|
|
switch ($transformation){ |
140
|
|
|
case "1": |
141
|
|
|
return mb_strtoupper($this->value); |
142
|
|
|
case "2": |
143
|
|
|
return mb_strtolower($this->value); |
144
|
|
|
case "3": |
145
|
|
|
return ucwords($this->value); |
146
|
|
|
default: |
147
|
|
|
return $this->value; |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.