GravityView  2.9.2
The best, easiest way to display Gravity Forms entries on your website.
class-gv-settings-view.php
Go to the documentation of this file.
1 <?php
2 namespace GV;
3 
4 /** If this file is called directly, abort. */
5 if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
6  die();
7 }
8 
9 /**
10  * The View Settings class.
11  */
12 class View_Settings extends Settings {
13  /**
14  * Retrieve an instance of the settings with default values.
15  * @param bool $detailed Whether to return detailed setting meta information or just the value.
16  *
17  * @api
18  * @since 2.0
19  *
20  * @return \GV\View_Settings
21  */
22  public static function with_defaults( $detailed = false ) {
23  $settings = new self();
24  $settings->update( self::defaults( $detailed ) );
25  return $settings;
26  }
27 
28  /**
29  * Retrieve the default View settings.
30  *
31  * @param bool $detailed Whether to return detailed setting meta information or just the value.
32  * @param string $group Retrieve settings of a particular group.
33  *
34  * @api
35  * @since 2.0
36  *
37  * @return array The default settings along with their values.
38  * @param[out] string $label Setting label shown in admin
39  * @param[out] string $type Gravity Forms field type
40  * @param[out] string $group The field group the setting is associated with. Default: "default"
41  * @param[out] mixed $value The default value for the setting
42  * @param[out] string $tooltip Tooltip displayed for the setting
43  * @param[out] boolean $show_in_shortcode Whether to show the setting in the shortcode configuration modal
44  * @param[out] array $options Array of values to use when generating select, multiselect, radio, or checkboxes fields
45  * @param[out] boolean $full_width True: Display the input and label together when rendering. False: Display label and input in separate columns when rendering.
46  */
47  public static function defaults( $detailed = false, $group = null ) {
48 
49  $default_settings = array_merge( array(
50  'id' => array(
51  'label' => __( 'View ID', 'gravityview' ),
52  'type' => 'number',
53  'group' => 'default',
54  'value' => NULL,
55  'tooltip' => NULL,
56  'show_in_shortcode' => false,
57  ),
58  'page_size' => array(
59  'label' => __( 'Number of entries per page', 'gravityview' ),
60  'type' => 'number',
61  'class' => 'small-text',
62  'group' => 'default',
63  'value' => 25,
64  'show_in_shortcode' => true,
65  ),
66  'offset' => array(
67  'label' => __( 'Offset entries starting from', 'gravityview' ),
68  'type' => 'number',
69  'class' => 'small-text',
70  'group' => 'default',
71  'value' => 0,
72  'show_in_shortcode' => true,
73  ),
74  'lightbox' => array(
75  'label' => __( 'Enable lightbox for images', 'gravityview' ),
76  'type' => 'checkbox',
77  'group' => 'default',
78  'value' => 1,
79  'tooltip' => __( 'If enabled, images will open full-size in a "lightbox". A lightbox displays images and videos by filling the screen and dimming out the rest of the web page.', 'gravityview' ),
80  'show_in_shortcode' => true,
81  'article' => array(
82  'id' => '5e9a1f8904286364bc98931f',
83  'url' => 'https://docs.gravityview.co/article/705-view-settings-enable-lightbox-for-images',
84  ),
85  ),
86  'show_only_approved' => array(
87  'label' => __( 'Show only approved entries', 'gravityview' ),
88  'type' => 'checkbox',
89  'group' => 'default',
90  'desc' => __( 'By default, only approved entries are displayed in a View. When enabled, this setting prevents unapproved or disapproved entries from appearing in results. If disabled, entries with all approval statuses will be visible, including disapproved entries.', 'gravityview' ),
91  'tooltip' => false,
92  'value' => 1,
93  'show_in_shortcode' => true,
94  'article' => array(
95  'id' => '5bad1a33042863158cc6d396',
96  'url' => 'https://docs.gravityview.co/article/490-entry-approval-gravity-forms',
97  ),
98  ),
99  'no_results_text' => array(
100  'label' => __( '"No Results" Text', 'gravityview' ),
101  'type' => 'text',
102  'group' => 'default',
103  'desc' => '',
104  'tooltip' => false,
105  'value' => '',
106  'placeholder' => __( 'No entries match your request.', 'gravityview' ),
107  'show_in_shortcode' => true,
108  'class' => 'widefat',
109  'full_width' => true,
110  ),
111  'no_search_results_text' => array(
112  'label' => __( '"No Search Results" Text', 'gravityview' ),
113  'type' => 'text',
114  'group' => 'default',
115  'desc' => '',
116  'tooltip' => false,
117  'value' => '',
118  'placeholder' => __( 'This search returned no results.', 'gravityview' ),
119  'show_in_shortcode' => true,
120  'class' => 'widefat',
121  'full_width' => true,
122  ),
123  'admin_show_all_statuses' => array(
124  'label' => __( 'Show all entries to administrators', 'gravityview' ),
125  'desc' => __( 'Administrators will be able to see entries with any approval status.', 'gravityview' ),
126  'tooltip' => __( 'Logged-out visitors and non-administrators will only see approved entries, while administrators will see entries with all statuses. This makes it easier for administrators to moderate entries from a View.', 'gravityview' ),
127  'requires' => 'show_only_approved',
128  'type' => 'checkbox',
129  'group' => 'default',
130  'value' => 0,
131  'show_in_shortcode' => false,
132  ),
133  'hide_until_searched' => array(
134  'label' => __( 'Hide View data until search is performed', 'gravityview' ),
135  'type' => 'checkbox',
136  'group' => 'default',
137  'tooltip' => __( 'When enabled it will only show any View entries after a search is performed.', 'gravityview' ),
138  'value' => 0,
139  'show_in_shortcode' => false,
140  'article' => array(
141  'id' => '5c772fa02c7d3a0cb9320a84',
142  'url' => 'https://docs.gravityview.co/article/536-how-to-hide-results-and-only-display-them-if-a-search-is-performed',
143  ),
144  ),
145  'hide_empty' => array(
146  'label' => __( 'Hide empty fields', 'gravityview' ),
147  'group' => 'default',
148  'type' => 'checkbox',
149  'desc' => __( 'When enabled, empty fields will be not be displayed. If disabled, fields and their labels will be displayed with no content.', 'gravityview' ),
150  'value' => 1,
151  'tooltip' => false,
152  'show_in_shortcode' => false,
153  ),
154  'hide_empty_single' => array(
155  'label' => __( 'Hide empty fields', 'gravityview' ),
156  'group' => 'default',
157  'type' => 'checkbox',
158  'desc' => __( 'When enabled, empty fields will be not be displayed. If disabled, fields and their labels will be displayed with no content.', 'gravityview' ),
159  'value' => 1,
160  'tooltip' => false,
161  'show_in_shortcode' => false,
162  ),
163  'edit_feeds' => array(
164  'label' => __( 'Feeds', 'gravityview' ),
165  'group' => 'default',
166  'type' => 'checkbox',
167  'value' => array(),
168  'show_in_shortcode' => false,
169  ),
170  'user_edit' => array(
171  'label' => __( 'Allow User Edit', 'gravityview' ), 'group' => 'default',
172  'desc' => __( 'Allow logged-in users to edit entries they created.', 'gravityview' ) . ' ' . sprintf( __( 'Administrators are able to %s regardless of this setting.', 'gravityview' ), _x( 'edit entries', 'an action that admins can perform', 'gravityview' ) ),
173  'value' => 0,
174  'tooltip' => __( 'Display "Edit Entry" fields to non-administrator users if they created the entry. Edit Entry fields will always be displayed to site administrators.', 'gravityview' ),
175  'type' => 'checkbox',
176  'show_in_shortcode' => true,
177  'article' => array(
178  'id' => '54c67bbbe4b07997ea3f3f6b',
179  'url' => 'https://docs.gravityview.co/article/77-user-edit-allow-users-to-edit-their-own-entries',
180  ),
181  ),
182  'unapprove_edit' => array(
183  'label' => __( 'Unapprove Entries After Edit', 'gravityview' ),
184  'group' => 'default',
185  'requires' => 'user_edit',
186  'desc' => __( 'When an entry is edited by a non-administrator, reset the approval status to "Unapproved".', 'gravityview' ),
187  'tooltip' => __( 'If the "Show only approved entries" setting is enabled, the entry will need to be re-approved by an administrator before it is shown in the View.', 'gravityview' ),
188  'value' => 0,
189  'type' => 'checkbox',
190  'show_in_shortcode' => true,
191  'article' => array(
192  'id' => '5ddd81d504286364bc923957',
193  'url' => 'https://docs.gravityview.co/article/657-unapproving-edited-entries-automatically',
194  ),
195  ),
196  'user_delete' => array(
197  'label' => __( 'Allow User Delete', 'gravityview' ),
198  'group' => 'default',
199  'desc' => __( 'Allow logged-in users to delete entries they created.', 'gravityview' ) . ' ' . sprintf( __( 'Administrators are able to %s regardless of this setting.', 'gravityview' ), _x( 'delete entries', 'an action that admins can perform', 'gravityview' ) ),
200  'value' => 0,
201  'tooltip' => __( 'Display "Delete Entry" fields to non-administrator users if they created the entry. Delete Entry fields will always be displayed to site administrators.', 'gravityview' ),
202  'type' => 'checkbox',
203  'show_in_shortcode' => true,
204  'article' => array(
205  'id' => '54c67bb9e4b0512429885512',
206  'url' => 'https://docs.gravityview.co/article/66-configuring-delete-entry',
207  ),
208  ),
209  'user_duplicate' => array(
210  'label' => __( 'Allow User Duplicate', 'gravityview' ),
211  'group' => 'default',
212  'desc' => __( 'Allow logged-in users to duplicate entries they created.', 'gravityview' ) . ' ' . sprintf( __( 'Administrators are able to %s regardless of this setting.', 'gravityview' ), _x( 'duplicate entries', 'an action that admins can perform', 'gravityview' ) ),
213  'value' => 0,
214  'tooltip' => __( 'Display "Duplicate Entry" fields to non-administrator users if they created the entry. Duplicate Entry fields will always be displayed to site administrators.', 'gravityview' ),
215  'article' => array(
216  'id' => '5df11eb704286364bc92bf36',
217  'url' => 'https://docs.gravityview.co/article/66-configuring-delete-entry',
218  'type' => 'inline',
219  ),
220  'type' => 'checkbox',
221  'show_in_shortcode' => true,
222  ),
223  'sort_field' => array(
224  'label' => __( 'Sort by field', 'gravityview' ),
225  'type' => 'select',
226  'desc' => __( 'By default, entries are sorted by Entry ID.', 'gravityview' ),
227  'value' => '',
228  'group' => 'sort',
229  'options' => array(
230  '' => __( 'Default', 'gravityview' ),
231  'date_created' => __( 'Date Created', 'gravityview' ),
232  ),
233  'show_in_shortcode' => true,
234  'article' => array(
235  'id' => '54c67bbbe4b051242988551a',
236  'url' => 'https://docs.gravityview.co/article/74-sorting-results-by-field-value',
237  ),
238  ),
239  'sort_direction' => array(
240  'label' => __( 'Sort direction', 'gravityview' ),
241  'type' => 'select',
242  'value' => 'ASC',
243  'group' => 'sort',
244  'options' => array(
245  'ASC' => __( 'ASC', 'gravityview' ),
246  'DESC' => __( 'DESC', 'gravityview' ),
247  ),
248  'show_in_shortcode' => true,
249  'article' => array(
250  'id' => '5c9d338a2c7d3a1544617f9b',
251  'url' => 'https://docs.gravityview.co/article/570-sorting-by-multiple-columns',
252  ),
253  ),
254  'sort_field_2' => array(
255  'label' => __( 'Sort by secondary field', 'gravityview' ),
256  'type' => 'select',
257  'value' => '',
258  'group' => 'sort',
259  'options' => array(
260  '' => __( 'Default', 'gravityview' ),
261  'date_created' => __( 'Date Created', 'gravityview' ),
262  ),
263  'requires_not' => 'sort_direction][=RAND', // ][ is for toggleRequired, so it ends in []
264  'show_in_shortcode' => true,
265  'article' => array(
266  'id' => '5c9d338a2c7d3a1544617f9b',
267  'url' => 'https://docs.gravityview.co/article/570-sorting-by-multiple-columns',
268  ),
269  ),
270  'sort_direction_2' => array(
271  'label' => __( 'Secondary sort direction', 'gravityview' ),
272  'type' => 'select',
273  'value' => 'ASC',
274  'group' => 'sort',
275  'options' => array(
276  'ASC' => __( 'ASC', 'gravityview' ),
277  'DESC' => __( 'DESC', 'gravityview' ),
278  ),
279  'requires_not' => 'sort_direction][=RAND', // ][ is for toggleRequired, so it ends in []
280  'show_in_shortcode' => true,
281  'article' => array(
282  'id' => '5c9d338a2c7d3a1544617f9b',
283  'url' => 'https://docs.gravityview.co/article/570-sorting-by-multiple-columns',
284  ),
285  ),
286  'sort_columns' => array(
287  'label' => __( 'Enable sorting by column', 'gravityview' ),
288  'left_label' => __( 'Column Sorting', 'gravityview' ),
289  'type' => 'checkbox',
290  'value' => false,
291  'group' => 'sort',
292  'tooltip' => NULL,
293  'show_in_shortcode' => true,
294  'show_in_template' => array( 'default_table', 'preset_business_data', 'preset_issue_tracker', 'preset_resume_board', 'preset_job_board' ),
295  'article' => array(
296  'id' => '54ee1246e4b034c37ea91c11',
297  'url' => 'https://docs.gravityview.co/article/230-enabling-the-table-column-sorting-feature',
298  ),
299  ),
300  'start_date' => array(
301  'label' => __( 'Filter by Start Date', 'gravityview' ),
302  'class' => 'gv-datepicker',
303  'desc' => __( 'Show entries submitted after this date. Supports relative dates, such as "-1 week" or "-1 month".', 'gravityview' ),
304  'type' => 'text',
305  'value' => '',
306  'group' => 'filter',
307  'show_in_shortcode' => true,
308  'article' => array(
309  'id' => '54c67bbbe4b0512429885520',
310  'url' => 'https://docs.gravityview.co/article/79-using-relative-start-dates-and-end-dates',
311  ),
312  ),
313  'end_date' => array(
314  'label' => __( 'Filter by End Date', 'gravityview' ),
315  'class' => 'gv-datepicker',
316  'desc' => __( 'Show entries submitted before this date. Supports relative dates, such as "now" or "-3 days".', 'gravityview' ),
317  'type' => 'text',
318  'value' => '',
319  'group' => 'filter',
320  'show_in_shortcode' => true,
321  'article' => array(
322  'id' => '54c67bbbe4b0512429885520',
323  'url' => 'https://docs.gravityview.co/article/79-using-relative-start-dates-and-end-dates',
324  ),
325  ),
326  'class' => array(
327  'label' => __( 'CSS Class', 'gravityview' ),
328  'desc' => __( 'CSS class to add to the wrapping HTML container.', 'gravityview' ),
329  'group' => 'default',
330  'type' => 'text',
331  'value' => '',
332  'show_in_shortcode' => false,
333  ),
334  'search_value' => array(
335  'label' => __( 'Search Value', 'gravityview' ),
336  'desc' => __( 'Define a default search value for the View', 'gravityview' ),
337  'type' => 'text',
338  'value' => '',
339  'group' => 'filter',
340  'show_in_shortcode' => false,
341  ),
342  'search_field' => array(
343  'label' => __( 'Search Field', 'gravityview' ),
344  'desc' => __( 'If Search Value is set, you can define a specific field to search in. Otherwise, all fields will be searched.', 'gravityview' ),
345  'type' => 'text',
346  'value' => '',
347  'group' => 'filter',
348  'show_in_shortcode' => false,
349  ),
350  'search_operator' => array(
351  'label' => __( 'Search Operator', 'gravityview' ),
352  'type' => 'operator',
353  'value' => 'contains',
354  'group' => 'filter',
355  'show_in_shortcode' => false,
356  ),
357  'single_title' => array(
358  'label' => __( 'Single Entry Title', 'gravityview' ),
359  'type' => 'text',
360  'desc' => __( 'When viewing a single entry, change the title of the page to this setting. Otherwise, the title will not change between the Multiple Entries and Single Entry views.', 'gravityview' ),
361  'group' => 'default',
362  'value' => '',
363  'show_in_shortcode' => false,
364  'full_width' => true,
365  'article' => array(
366  'id' => '54c67bcee4b07997ea3f3f9a',
367  'url' => 'https://docs.gravityview.co/article/121-changing-the-single-entry-page-title',
368  ),
369  ),
370  'back_link_label' => array(
371  'label' => __( 'Back Link Label', 'gravityview' ),
372  'group' => 'default',
373  'desc' => __( 'The text of the link that returns to the multiple entries view.', 'gravityview' ),
374  'type' => 'text',
375  'value' => '',
376  'placeholder' => __( '&larr; Go back', 'gravityview' ),
377  'class' => 'widefat',
378  'merge_tags' => 'force',
379  'show_in_shortcode' => false,
380  'full_width' => true,
381  ),
382  'edit_redirect' => array(
383  'label' => __( 'Redirect After Editing', 'gravityview' ),
384  'group' => 'default',
385  'desc' => __( 'The page to redirect to after editing an entry.', 'gravityview' ),
386  'type' => 'select',
387  'value' => '',
388  'options' => array(
389  '' => __( 'Stay on Edit Entry', 'gravityview' ),
390  '0' => __( 'Redirect to Single Entry', 'gravityview' ),
391  '1' => __( 'Redirect to Multiple Entries', 'gravityview' ),
392  '2' => __( 'Redirect to URL', 'gravityview' ),
393  )
394  ),
395  'edit_return_context' => array(
396  'label' => __( 'Editing Returns To&hellip;', 'gravityview' ),
397  'type' => 'radio',
398  'desc' => __( 'After editing an entry or clicking Cancel, where should the user be sent?', 'gravityview' ),
399  'group' => 'default',
400  'value' => 'single',
401  'options' => array(
402  'multiple' => __( 'Multiple Entries', 'gravityview' ),
403  'single' => __( 'Single Entry', 'gravityview' ),
404  'custom' => __( 'Other URL', 'gravityview' ),
405  ),
406  'show_in_shortcode' => false,
407  'full_width' => true,
408  'article' => array(
409  'id' => '5e9a3e0c2c7d3a7e9aeb2efb',
410  'url' => 'https://docs.gravityview.co/article/707-view-settings-redirect-after-editing',
411  ),
412  ),
413  'edit_redirect_url' => array(
414  'label' => __( 'Edit Entry Redirect URL', 'gravityview' ),
415  'group' => 'default',
416  'desc' => __( 'After editing an entry, the user will be taken to this URL.', 'gravityview' ),
417  'type' => 'text',
418  'class' => 'code widefat',
419  'value' => '',
420  'requires' => 'edit_redirect=2',
421  'merge_tags' => 'force',
422  ),
423  'edit_locking' => array(
424  'label' => __( 'Enable Edit Locking', 'gravityview' ),
425  'group' => 'default',
426  'desc' => __( 'Prevent multiple users from editing the same entry at the same time.', 'gravityview' ),
427  'type' => 'checkbox',
428  'full_width' => true,
429  'class' => 'code widefat',
430  'value' => true,
431  'article' => array(
432  'id' => '5e4449d72c7d3a7e9ae7a54c',
433  'url' => 'https://docs.gravityview.co/article/676-entry-locking',
434  ),
435  ),
436  'embed_only' => array(
437  'label' => __( 'Prevent Direct Access', 'gravityview' ),
438  'group' => 'default',
439  'desc' => __( 'Only allow access to this View when embedded using the shortcode.', 'gravityview' ),
440  'type' => 'checkbox',
441  'value' => '',
442  'tooltip' => false,
443  'show_in_shortcode' => false,
444  'full_width' => true,
445  ),
446  ), ( gravityview()->plugin->supports( Plugin::FEATURE_REST ) && ( gravityview()->plugin->settings->get( 'rest_api' ) === '1' ) ) ?
447  array(
448  'rest_disable' => array(
449  'label' => __( 'Prevent REST Access', 'gravityview' ),
450  'group' => 'default',
451  'desc' => __( 'Disable REST access to this View.', 'gravityview' ),
452  'type' => 'checkbox',
453  'value' => '',
454  'tooltip' => false,
455  'show_in_shortcode' => false,
456  'full_width' => true,
457  ),
458  ) : array(),
459  ( gravityview()->plugin->supports( Plugin::FEATURE_REST ) && ( gravityview()->plugin->settings->get( 'rest_api' ) !== '1' ) ) ?
460  array(
461  'rest_enable' => array(
462  'label' => __( 'Allow REST Access', 'gravityview' ),
463  'group' => 'default',
464  'desc' => __( 'Enable REST access to this View.', 'gravityview' ),
465  'type' => 'checkbox',
466  'value' => '',
467  'tooltip' => false,
468  'show_in_shortcode' => false,
469  'full_width' => true,
470  ),
471  ) : array(),
472  array(
473  'csv_enable' => array(
474  'label' => __( 'Allow CSV Access', 'gravityview' ),
475  'group' => 'default',
476  'desc' => __( 'Enable CSV access to this View.', 'gravityview' ),
477  'type' => 'checkbox',
478  'value' => '',
479  'tooltip' => __( 'If enabled, entries can be exported for this View by adding "/csv/" to the View URL. Each configured field will be a column in the exported CSV.', 'gravityview' ),
480  'show_in_shortcode' => false,
481  'full_width' => true,
482  'article' => array(
483  'id' => '5bad2a0c042863158cc6d4ac',
484  'url' => 'https://docs.gravityview.co/article/491-csv-export',
485  ),
486  ),
487  ),
488  array(
489  'csv_nolimit' => array(
490  'label' => __( 'Show all in CSV', 'gravityview' ),
491  'group' => 'default',
492  'requires' => 'csv_enable',
493  'desc' => __( 'Do not limit the number of entries output in the CSV.', 'gravityview' ),
494  'type' => 'checkbox',
495  'value' => '',
496  'tooltip' => false,
497  'show_in_shortcode' => false,
498  'full_width' => true,
499  ),
500  ),
501  array(
502  'post_id' => array(
503  'type' => 'number',
504  'value' => '',
505  'show_in_shortcode' => false,
506  ),
507  ) );
508 
509  if ( version_compare( \GFCommon::$version, '2.3-beta-4', '>=' ) ) {
510  $default_settings['sort_direction']['options']['RAND'] = __( 'Random', 'gravityview' );
511  }
512 
513  /**
514  * @filter `gravityview_default_args` Modify the default settings for new Views
515  * @param[in,out] array $default_args Array of default args.
516  * @deprecated
517  * @see filter `gravityview/view/settings/defaults`
518  */
519  $default_settings = apply_filters( 'gravityview_default_args', $default_settings );
520 
521  /**
522  * @filter `gravityview/view/defaults` Modify the default settings for new Views
523  * @param[in,out] array $default_settings Array of default settings.
524  */
525  $default_settings = apply_filters( 'gravityview/view/settings/defaults', $default_settings );
526 
527  // By default, we only want the key => value pairing, not the whole array.
528  if ( ! $detailed ) {
529  $defaults = array();
530  foreach( $default_settings as $key => $value ) {
531  $defaults[ $key ] = $value['value'];
532  }
533  return $defaults;
534 
535  // But sometimes, we want all the details.
536  } else {
537  foreach ( $default_settings as $key => $value ) {
538 
539  // If the $group argument is set for the method,
540  // ignore any settings that aren't in that group.
541  if ( ! empty( $group ) && is_string( $group ) ) {
542  if ( empty( $value['group'] ) || $value['group'] !== $group ) {
543  unset( $default_settings[ $key ] );
544  }
545  }
546  }
547  return $default_settings;
548  }
549  }
550 
551  /**
552  * Turn to an $atts array as used around the old codebase.
553  *
554  * @internal
555  * @deprecated
556  *
557  * @return array
558  */
559  public function as_atts() {
560  $defaults = array_keys( self::defaults() );
561  $_this = &$this;
562  return array_combine( $defaults, array_map( function( $key ) use ( $_this ) {
563  return $_this->get( $key );
564  }, $defaults ) );
565  }
566 }
If this file is called directly, abort.
static with_defaults( $detailed=false)
Retrieve an instance of the settings with default values.
gravityview()
Definition: _stubs.php:26
If this file is called directly, abort.
defaults()
Default settings.
if(empty( $field_settings['email_field'])) $settings
as_atts()
Turn to an $atts array as used around the old codebase.
static defaults( $detailed=false, $group=null)
Retrieve the default View settings.