|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class GravityView_Admin_View_Field extends GravityView_Admin_View_Item { |
|
4
|
|
|
|
|
5
|
|
|
private $label_type = 'field'; |
|
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
protected function additional_info() { |
|
8
|
|
|
|
|
9
|
|
|
$field_info = ''; |
|
10
|
|
|
|
|
11
|
|
|
$field_info_items = array(); |
|
12
|
|
|
|
|
13
|
|
|
// Fields with IDs, not like Source URL or Entry ID |
|
14
|
|
|
if( is_numeric( $this->id ) ) { |
|
15
|
|
|
|
|
16
|
|
|
$field_type_title = GFCommon::get_field_type_title( $this->item['input_type'] ); |
|
17
|
|
|
|
|
18
|
|
|
$field_info_items[] = array( |
|
19
|
|
|
'value' => sprintf( __('Type: %s', 'gravityview'), $field_type_title ) |
|
|
|
|
|
|
20
|
|
|
); |
|
21
|
|
|
|
|
22
|
|
|
$field_info_items[] = array( |
|
23
|
|
|
'value' => sprintf( __('Field ID: %s', 'gravityview'), $this->id ), |
|
|
|
|
|
|
24
|
|
|
); |
|
25
|
|
|
|
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
if( !empty( $this->item['desc'] ) ) { |
|
|
|
|
|
|
29
|
|
|
$field_info_items[] = array( |
|
30
|
|
|
'value' => $this->item['desc'] |
|
|
|
|
|
|
31
|
|
|
); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
if( !empty( $this->item['adminLabel'] ) ) { |
|
|
|
|
|
|
35
|
|
|
$field_info_items[] = array( |
|
36
|
|
|
'value' => sprintf( __('Admin Label: %s', 'gravityview' ), $this->item['adminLabel'] ), |
|
|
|
|
|
|
37
|
|
|
'class' => 'gv-sublabel' |
|
|
|
|
|
|
38
|
|
|
); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
return $field_info_items; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
class GravityView_Admin_View_Widget extends GravityView_Admin_View_Item { |
|
47
|
|
|
|
|
48
|
|
|
private $label_type = 'widget'; |
|
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
protected function additional_info() { |
|
51
|
|
|
|
|
52
|
|
|
$field_info = ''; |
|
53
|
|
|
$field_info_items = array(); |
|
54
|
|
|
|
|
55
|
|
|
if( !empty( $this->item['description'] ) ) { |
|
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
$field_info_items[] = array( |
|
58
|
|
|
'value' => $this->item['description'] |
|
|
|
|
|
|
59
|
|
|
); |
|
60
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
return $field_info_items; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* A field or widget in GravityView view configuration |
|
70
|
|
|
*/ |
|
71
|
|
|
class GravityView_Admin_View_Item { |
|
72
|
|
|
|
|
73
|
|
|
protected $title; |
|
74
|
|
|
protected $id; |
|
75
|
|
|
protected $subtitle; |
|
76
|
|
|
protected $settings_html; |
|
77
|
|
|
private $label_type; |
|
78
|
|
|
protected $item; |
|
79
|
|
|
|
|
80
|
|
|
function __construct( $title = '', $field_id, $item = array(), $settings = array() ) { |
|
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
// Backward compat |
|
83
|
|
|
if( !empty( $item['type'] ) ) { |
|
|
|
|
|
|
84
|
|
|
$item['input_type'] = $item['type']; |
|
85
|
|
|
unset( $item['type'] ); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
// Prevent items from not having index set |
|
89
|
|
|
$item = wp_parse_args( $item, array( |
|
90
|
|
|
'label_text' => $title, |
|
91
|
|
|
'field_id' => NULL, |
|
|
|
|
|
|
92
|
|
|
'parent_label' => NULL, |
|
|
|
|
|
|
93
|
|
|
'label_type' => NULL, |
|
|
|
|
|
|
94
|
|
|
'input_type' => NULL, |
|
|
|
|
|
|
95
|
|
|
'settings_html' => NULL, |
|
|
|
|
|
|
96
|
|
|
'adminLabel' => NULL, |
|
|
|
|
|
|
97
|
|
|
'adminOnly' => NULL, |
|
|
|
|
|
|
98
|
|
|
'subtitle' => NULL, |
|
|
|
|
|
|
99
|
|
|
)); |
|
100
|
|
|
|
|
101
|
|
|
$this->title = $title; |
|
102
|
|
|
$this->item = $item; |
|
103
|
|
|
$this->id = $field_id; |
|
104
|
|
|
$this->settings = $settings; |
|
|
|
|
|
|
105
|
|
|
$this->label_type = $item['label_type']; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* When echoing this class, print the HTML output |
|
110
|
|
|
* @return string HTML output of the class |
|
111
|
|
|
*/ |
|
112
|
|
|
public function __toString() { |
|
113
|
|
|
|
|
114
|
|
|
return $this->getOutput(); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Overridden by child classes |
|
119
|
|
|
* @return array Array of content with arrays for each item. Those arrays have `value`, `label` and (optional) `class` keys |
|
120
|
|
|
*/ |
|
121
|
|
|
protected function additional_info() { |
|
122
|
|
|
return array(); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Generate the output for a field based on the additional_info() output |
|
127
|
|
|
* |
|
128
|
|
|
* @see GravityView_Admin_View_Item::additional_info() |
|
129
|
|
|
* @param boolean $html Display HTML output? If yes, output is wrapped in spans. If no, plaintext. |
|
130
|
|
|
* @return string|null If empty, return null. Otherwise, return output HTML/text. |
|
131
|
|
|
*/ |
|
132
|
|
|
protected function get_item_info( $html = true ) { |
|
133
|
|
|
|
|
134
|
|
|
$output = NULL; |
|
|
|
|
|
|
135
|
|
|
$field_info_items = $this->additional_info(); |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @filter `gravityview_admin_label_item_info` Tap in to modify the field information displayed next to an item |
|
139
|
|
|
* @param array $field_info_items Additional information to display in a field |
|
140
|
|
|
* @param GravityView_Admin_View_Field $this Field shown in the admin |
|
141
|
|
|
*/ |
|
142
|
|
|
$field_info_items = apply_filters( 'gravityview_admin_label_item_info', $field_info_items, $this ); |
|
143
|
|
|
|
|
144
|
|
|
if( $html ) { |
|
145
|
|
|
|
|
146
|
|
|
foreach ( $field_info_items as $item ) { |
|
147
|
|
|
$class = isset($item['class']) ? sanitize_html_class( $item['class'] ).' description' : 'description'; |
|
|
|
|
|
|
148
|
|
|
// Add the title in case the value's long, in which case, it'll be truncated by CSS. |
|
149
|
|
|
$output .= '<span class="'.$class.'">'; |
|
150
|
|
|
$output .= esc_html( $item['value'] ); |
|
151
|
|
|
$output .= '</span>'; |
|
152
|
|
|
} |
|
|
|
|
|
|
153
|
|
|
|
|
154
|
|
|
} else { |
|
155
|
|
|
|
|
156
|
|
|
$values = wp_list_pluck( $field_info_items, 'value' ); |
|
157
|
|
|
|
|
158
|
|
|
$output = esc_html( implode(', ', $values) ); |
|
|
|
|
|
|
159
|
|
|
|
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
return empty( $output ) ? NULL : $output; |
|
|
|
|
|
|
163
|
|
|
|
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* Generate HTML for field or a widget modal |
|
168
|
|
|
* |
|
169
|
|
|
* @return string |
|
170
|
|
|
*/ |
|
171
|
|
|
function getOutput() { |
|
|
|
|
|
|
172
|
|
|
|
|
173
|
|
|
$settings_title = sprintf(__('Configure %s Settings', 'gravityview'), ucfirst($this->label_type)); |
|
|
|
|
|
|
174
|
|
|
$delete_title = sprintf(__('Remove %s', 'gravityview'), ucfirst($this->label_type)); |
|
|
|
|
|
|
175
|
|
|
$single_link_title = __('This field links to the Single Entry', 'gravityview'); |
|
|
|
|
|
|
176
|
|
|
|
|
177
|
|
|
// $settings_html will just be hidden inputs if empty. Otherwise, it'll have an <ul>. Ugly hack, I know. |
|
178
|
|
|
// TODO: Un-hack this |
|
179
|
|
|
$hide_settings_link = ( empty( $this->item['settings_html'] ) || strpos( $this->item['settings_html'], '<!-- No Options -->') > 0 ) ? 'hide-if-js' : ''; |
|
|
|
|
|
|
180
|
|
|
$settings_link = sprintf( '<a href="#settings" class="dashicons-admin-generic dashicons %s" title="%s"></a>', $hide_settings_link, esc_attr( $settings_title ) ); |
|
181
|
|
|
|
|
182
|
|
|
// Should we show the icon that the field is being used as a link to single entry? |
|
183
|
|
|
$hide_show_as_link_class = empty( $this->settings['show_as_link'] ) ? 'hide-if-js' : ''; |
|
|
|
|
|
|
184
|
|
|
$show_as_link = '<span class="dashicons dashicons-admin-links '.$hide_show_as_link_class.'" title="'.esc_attr( $single_link_title ).'"></span>'; |
|
185
|
|
|
|
|
186
|
|
|
// When a field label is empty, use the Field ID |
|
187
|
|
|
$label = empty( $this->title ) ? sprintf( _x('Field #%s (No Label)', 'Label in field picker for empty label', 'gravityview'), $this->id ) : $this->title; |
|
|
|
|
|
|
188
|
|
|
|
|
189
|
|
|
// If there's a custom label, and show label is checked, use that as the field heading |
|
190
|
|
|
if( !empty( $this->settings['custom_label'] ) && !empty( $this->settings['show_label'] ) ) { |
|
|
|
|
|
|
191
|
|
|
$label = $this->settings['custom_label']; |
|
|
|
|
|
|
192
|
|
|
} else if( !empty( $this->item['customLabel'] ) ) { |
|
|
|
|
|
|
193
|
|
|
$label = $this->item['customLabel']; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
$output = '<h5 class="selectable gfield field-id-'.esc_attr($this->id).'">'; |
|
|
|
|
|
|
197
|
|
|
|
|
198
|
|
|
$label = esc_attr( $label ); |
|
199
|
|
|
|
|
200
|
|
|
if( !empty( $this->item['parent'] ) ) { |
|
|
|
|
|
|
201
|
|
|
$label .= ' <small>('.esc_attr( $this->item['parent']['label'] ) .')</small>'; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
// Name of field / widget |
|
205
|
|
|
$output .= '<span class="gv-field-label" data-original-title="'.esc_attr( $label ).'" title="'. $this->get_item_info( false ) .'">'. $label . '</span>'; |
|
206
|
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
208
|
|
|
$output .= '<span class="gv-field-controls">'.$settings_link.$show_as_link.'<a href="#remove" class="dashicons-dismiss dashicons" title="'.esc_attr( $delete_title ) .'"></a></span>'; |
|
209
|
|
|
|
|
210
|
|
|
// Displays only in the field/widget picker. |
|
211
|
|
|
if( $field_info = $this->get_item_info() ) { |
|
212
|
|
|
$output .= '<span class="gv-field-info">'.$field_info.'</span>'; |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
$output .= '</h5>'; |
|
216
|
|
|
|
|
217
|
|
|
$container_class = !empty( $this->item['parent'] ) ? ' gv-child-field' : ''; |
|
|
|
|
|
|
218
|
|
|
|
|
219
|
|
|
$output = '<div data-fieldid="'.esc_attr($this->id).'" data-inputtype="'.esc_attr( $this->item['input_type'] ).'" class="gv-fields'.$container_class.'">'.$output.$this->item['settings_html'].'</div>'; |
|
|
|
|
|
|
220
|
|
|
|
|
221
|
|
|
return $output; |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
} |
|
225
|
|
|
|