|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package Pods\Fields |
|
4
|
|
|
*/ |
|
5
|
|
|
class PodsField_Icon extends PodsField { |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Field Type Identifier |
|
9
|
|
|
* |
|
10
|
|
|
* @var string |
|
11
|
|
|
* @since 2.0 |
|
12
|
|
|
*/ |
|
13
|
|
|
public static $type = 'icon'; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Field Type Label |
|
17
|
|
|
* |
|
18
|
|
|
* @var string |
|
19
|
|
|
* @since 2.0 |
|
20
|
|
|
*/ |
|
21
|
|
|
public static $label = 'Icon Picker'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Field Type Preparation |
|
25
|
|
|
* |
|
26
|
|
|
* @var string |
|
27
|
|
|
* @since 2.0 |
|
28
|
|
|
*/ |
|
29
|
|
|
public static $prepare = '%s'; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Do things like register/enqueue scripts and stylesheets |
|
33
|
|
|
* |
|
34
|
|
|
* @since 2.0 |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct () { |
|
37
|
|
|
self::$label = __( 'Icon Picker', 'pods' ); |
|
38
|
|
|
|
|
39
|
|
|
// Load the icon picker library |
|
40
|
|
|
if ( ! class_exists( 'Icon_Picker' ) ) { |
|
41
|
|
|
require_once PODS_DIR . '/vendor/kucrut/icon-picker/icon-picker.php'; |
|
42
|
|
|
} |
|
43
|
|
|
$icon_picker = Icon_Picker::instance(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Add options and set defaults to |
|
48
|
|
|
* |
|
49
|
|
|
* |
|
50
|
|
|
* @return array |
|
|
|
|
|
|
51
|
|
|
* @since 2.0 |
|
52
|
|
|
*/ |
|
53
|
|
|
public function options () { |
|
54
|
|
|
$options = array( |
|
55
|
|
|
self::$type . '_repeatable' => array( |
|
56
|
|
|
'label' => __( 'Repeatable Field', 'pods' ), |
|
57
|
|
|
'default' => 0, |
|
58
|
|
|
'type' => 'boolean', |
|
59
|
|
|
'help' => __( 'Making a field repeatable will add controls next to the field which allows users to Add/Remove/Reorder additional values. These values are saved in the database as an array, so searching and filtering by them may require further adjustments".', 'pods' ), |
|
60
|
|
|
'boolean_yes_label' => '', |
|
61
|
|
|
'dependency' => true, |
|
62
|
|
|
'developer_mode' => true |
|
63
|
|
|
), |
|
64
|
|
|
'output_options' => array( |
|
65
|
|
|
'label' => __( 'Icon libraries', 'pods' ), |
|
66
|
|
|
'group' => array( |
|
|
|
|
|
|
67
|
|
|
) |
|
68
|
|
|
), |
|
69
|
|
|
); |
|
70
|
|
|
|
|
71
|
|
|
return $options; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Define the current field's schema for DB table storage |
|
76
|
|
|
* |
|
77
|
|
|
* @param array $options |
|
|
|
|
|
|
78
|
|
|
* |
|
79
|
|
|
* @return string |
|
80
|
|
|
* @since 2.0 |
|
81
|
|
|
*/ |
|
82
|
|
|
public function schema ( $options = null ) { |
|
83
|
|
|
$schema = 'LONGTEXT'; |
|
84
|
|
|
return $schema; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Change the way the value of the field is displayed with Pods::get |
|
89
|
|
|
* |
|
90
|
|
|
* @param mixed $value |
|
91
|
|
|
* @param string $name |
|
|
|
|
|
|
92
|
|
|
* @param array $options |
|
|
|
|
|
|
93
|
|
|
* @param array $pod |
|
|
|
|
|
|
94
|
|
|
* @param int $id |
|
|
|
|
|
|
95
|
|
|
* |
|
96
|
|
|
* @return mixed|null|string |
|
97
|
|
|
* @since 2.0 |
|
98
|
|
|
*/ |
|
99
|
|
|
public function display ( $value = null, $name = null, $options = null, $pod = null, $id = null ) { |
|
100
|
|
|
//$value = $this->strip_html( $value, $options ); |
|
|
|
|
|
|
101
|
|
|
//$value = icon_picker_get_icon_url( $value ); |
|
|
|
|
|
|
102
|
|
|
|
|
103
|
|
|
return $value; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Customize output of the form field |
|
108
|
|
|
* |
|
109
|
|
|
* @param string $name |
|
110
|
|
|
* @param mixed $value |
|
111
|
|
|
* @param array $options |
|
|
|
|
|
|
112
|
|
|
* @param array $pod |
|
|
|
|
|
|
113
|
|
|
* @param int $id |
|
|
|
|
|
|
114
|
|
|
* |
|
115
|
|
|
* @since 2.0 |
|
116
|
|
|
*/ |
|
117
|
|
|
public function input ( $name, $value = null, $options = null, $pod = null, $id = null ) { |
|
118
|
|
|
$options = (array) $options; |
|
119
|
|
|
$form_field_type = PodsForm::$field_type; |
|
120
|
|
|
|
|
121
|
|
|
if ( isset( $options[ 'name' ] ) && false === PodsForm::permission( self::$type, $options[ 'name' ], $options, null, $pod, $id ) ) { |
|
122
|
|
|
if ( pods_var( 'read_only', $options, false ) ) { |
|
123
|
|
|
$options[ 'readonly' ] = true; |
|
124
|
|
|
} else { |
|
125
|
|
|
return; |
|
126
|
|
|
} |
|
127
|
|
|
} elseif ( ! pods_has_permissions( $options ) && pods_var( 'read_only', $options, false ) ) { |
|
128
|
|
|
$options[ 'readonly' ] = true; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
pods_view( PODS_DIR . 'ui/fields/icon.php', compact( array_keys( get_defined_vars() ) ) ); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Validate a value before it's saved |
|
136
|
|
|
* |
|
137
|
|
|
* @param mixed $value |
|
138
|
|
|
* @param string $name |
|
|
|
|
|
|
139
|
|
|
* @param array $options |
|
|
|
|
|
|
140
|
|
|
* @param array $fields |
|
|
|
|
|
|
141
|
|
|
* @param array $pod |
|
|
|
|
|
|
142
|
|
|
* @param int $id |
|
|
|
|
|
|
143
|
|
|
* |
|
144
|
|
|
* @param null $params |
|
145
|
|
|
* @return array|bool |
|
146
|
|
|
* @since 2.0 |
|
147
|
|
|
*/ |
|
148
|
|
|
public function validate ( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) { |
|
149
|
|
|
$errors = array(); |
|
150
|
|
|
|
|
151
|
|
|
$check = $this->pre_save( $value, $id, $name, $options, $fields, $pod, $params ); |
|
152
|
|
|
|
|
153
|
|
|
if ( empty( $check ) ) { |
|
154
|
|
|
if ( pods_var( 'required', $options ) ) { |
|
155
|
|
|
$errors[] = __( 'This field is required.', 'pods' ); |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
if ( ! empty( $errors ) ) { |
|
160
|
|
|
return $errors; |
|
|
|
|
|
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
return true; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* Change the value or perform actions after validation but before saving to the DB |
|
168
|
|
|
* |
|
169
|
|
|
* @param mixed $value |
|
170
|
|
|
* @param int $id |
|
|
|
|
|
|
171
|
|
|
* @param string $name |
|
|
|
|
|
|
172
|
|
|
* @param array $options |
|
|
|
|
|
|
173
|
|
|
* @param array $fields |
|
|
|
|
|
|
174
|
|
|
* @param array $pod |
|
|
|
|
|
|
175
|
|
|
* @param object $params |
|
|
|
|
|
|
176
|
|
|
* |
|
177
|
|
|
* @return mixed|string |
|
178
|
|
|
* @since 2.0 |
|
179
|
|
|
*/ |
|
180
|
|
|
public function pre_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) { |
|
181
|
|
|
|
|
182
|
|
|
$value = array_intersect_key( $value, array( 'type' => '', 'icon' => '' ) ); |
|
183
|
|
|
|
|
184
|
|
|
if ( empty( $value['type'] ) || empty( $value['icon'] ) ) { |
|
185
|
|
|
$value = ''; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
$value = array_map( 'strip_tags', $value ); |
|
189
|
|
|
|
|
190
|
|
|
return $value; |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* Customize the Pods UI manage table column output |
|
195
|
|
|
* |
|
196
|
|
|
* @param int $id |
|
197
|
|
|
* @param mixed $value |
|
198
|
|
|
* @param string $name |
|
|
|
|
|
|
199
|
|
|
* @param array $options |
|
|
|
|
|
|
200
|
|
|
* @param array $fields |
|
|
|
|
|
|
201
|
|
|
* @param array $pod |
|
|
|
|
|
|
202
|
|
|
* |
|
203
|
|
|
* @return mixed|string |
|
204
|
|
|
* @since 2.0 |
|
205
|
|
|
*/ |
|
206
|
|
|
public function ui ( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) { |
|
|
|
|
|
|
207
|
|
|
/*$value = $this->strip_html( $value, $options ); |
|
|
|
|
|
|
208
|
|
|
|
|
209
|
|
|
if ( 0 == pods_var( self::$type . '_allow_html', $options, 0, null, true ) ) |
|
210
|
|
|
$value = wp_trim_words( $value );*/ |
|
211
|
|
|
|
|
212
|
|
|
return $value; |
|
213
|
|
|
} |
|
214
|
|
|
} |
|
215
|
|
|
|
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.