GravityView  2.1.1
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' => NULL,
80  'show_in_shortcode' => true,
81  ),
82  'show_only_approved' => array(
83  'label' => __( 'Show only approved entries', 'gravityview' ),
84  'type' => 'checkbox',
85  'group' => 'default',
86  'value' => 0,
87  'show_in_shortcode' => true,
88  ),
89  'admin_show_all_statuses' => array(
90  'label' => __( 'Show all entries to administrators', 'gravityview' ),
91  'desc' => __( 'Administrators will be able to see entries with any approval status.', 'gravityview' ),
92  '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' ),
93  'requires' => 'show_only_approved',
94  'type' => 'checkbox',
95  'group' => 'default',
96  'value' => 0,
97  'show_in_shortcode' => false,
98  ),
99  'hide_until_searched' => array(
100  'label' => __( 'Hide View data until search is performed', 'gravityview' ),
101  'type' => 'checkbox',
102  'group' => 'default',
103  'tooltip' => __( 'When enabled it will only show any View entries after a search is performed.', 'gravityview' ),
104  'value' => 0,
105  'show_in_shortcode' => false,
106  ),
107  'hide_empty' => array(
108  'label' => __( 'Hide empty fields', 'gravityview' ),
109  'group' => 'default',
110  'type' => 'checkbox',
111  'value' => 1,
112  'show_in_shortcode' => false,
113  ),
114  'user_edit' => array(
115  'label' => __( 'Allow User Edit', 'gravityview' ),
116  'group' => 'default',
117  'desc' => __( 'Allow logged-in users to edit entries they created.', 'gravityview' ),
118  'value' => 0,
119  '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' ),
120  'type' => 'checkbox',
121  'show_in_shortcode' => true,
122  ),
123  'unapprove_edit' => array(
124  'label' => __( 'Unapprove Entries After Edit', 'gravityview' ),
125  'group' => 'default',
126  'requires' => 'user_edit',
127  'desc' => __( 'When an entry is edited by a non-administrator, reset the approval status to "Unapproved".', 'gravityview' ),
128  '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' ),
129  'value' => 0,
130  'type' => 'checkbox',
131  'show_in_shortcode' => true,
132  ),
133  'user_delete' => array(
134  'label' => __( 'Allow User Delete', 'gravityview' ),
135  'group' => 'default',
136  'desc' => __( 'Allow logged-in users to delete entries they created.', 'gravityview' ),
137  'value' => 0,
138  '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' ),
139  'type' => 'checkbox',
140  'show_in_shortcode' => true,
141  ),
142  'sort_field' => array(
143  'label' => __( 'Sort by field', 'gravityview' ),
144  'type' => 'select',
145  'value' => '',
146  'group' => 'sort',
147  'options' => array(
148  '' => __( 'Default', 'gravityview' ),
149  'date_created' => __( 'Date Created', 'gravityview' ),
150  ),
151  'show_in_shortcode' => true,
152  ),
153  'sort_direction' => array(
154  'label' => __( 'Sort direction', 'gravityview' ),
155  'type' => 'select',
156  'value' => 'ASC',
157  'group' => 'sort',
158  'options' => array(
159  'ASC' => __( 'ASC', 'gravityview' ),
160  'DESC' => __( 'DESC', 'gravityview' ),
161  ),
162  'show_in_shortcode' => true,
163  ),
164  'sort_columns' => array(
165  'label' => __( 'Enable sorting by column', 'gravityview' ),
166  'left_label' => __( 'Column Sorting', 'gravityview' ),
167  'type' => 'checkbox',
168  'value' => false,
169  'group' => 'sort',
170  'tooltip' => NULL,
171  'show_in_shortcode' => true,
172  'show_in_template' => array( 'default_table', 'preset_business_data', 'preset_issue_tracker', 'preset_resume_board', 'preset_job_board' ),
173  ),
174  'start_date' => array(
175  'label' => __( 'Filter by Start Date', 'gravityview' ),
176  'class' => 'gv-datepicker',
177  'desc' => __( 'Show entries submitted after this date. Supports relative dates, such as "-1 week" or "-1 month".', 'gravityview' ),
178  'type' => 'text',
179  'value' => '',
180  'group' => 'filter',
181  'show_in_shortcode' => true,
182  ),
183  'end_date' => array(
184  'label' => __( 'Filter by End Date', 'gravityview' ),
185  'class' => 'gv-datepicker',
186  'desc' => __( 'Show entries submitted before this date. Supports relative dates, such as "now" or "-3 days".', 'gravityview' ),
187  'type' => 'text',
188  'value' => '',
189  'group' => 'filter',
190  'show_in_shortcode' => true,
191  ),
192  'class' => array(
193  'label' => __( 'CSS Class', 'gravityview' ),
194  'desc' => __( 'CSS class to add to the wrapping HTML container.', 'gravityview' ),
195  'group' => 'default',
196  'type' => 'text',
197  'value' => '',
198  'show_in_shortcode' => false,
199  ),
200  'search_value' => array(
201  'label' => __( 'Search Value', 'gravityview' ),
202  'desc' => __( 'Define a default search value for the View', 'gravityview' ),
203  'type' => 'text',
204  'value' => '',
205  'group' => 'filter',
206  'show_in_shortcode' => false,
207  ),
208  'search_field' => array(
209  'label' => __( 'Search Field', 'gravityview' ),
210  'desc' => __( 'If Search Value is set, you can define a specific field to search in. Otherwise, all fields will be searched.', 'gravityview' ),
211  'type' => 'text',
212  'value' => '',
213  'group' => 'filter',
214  'show_in_shortcode' => false,
215  ),
216  'search_operator' => array(
217  'label' => __( 'Search Operator', 'gravityview' ),
218  'type' => 'operator',
219  'value' => 'contains',
220  'group' => 'filter',
221  'show_in_shortcode' => false,
222  ),
223  'single_title' => array(
224  'label' => __( 'Single Entry Title', 'gravityview' ),
225  'type' => 'text',
226  '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' ),
227  'group' => 'default',
228  'value' => '',
229  'show_in_shortcode' => false,
230  'full_width' => true,
231  ),
232  'back_link_label' => array(
233  'label' => __( 'Back Link Label', 'gravityview' ),
234  'group' => 'default',
235  'desc' => __( 'The text of the link that returns to the multiple entries view.', 'gravityview' ),
236  'type' => 'text',
237  'value' => '',
238  'show_in_shortcode' => false,
239  'full_width' => true,
240  ),
241  'embed_only' => array(
242  'label' => __( 'Prevent Direct Access', 'gravityview' ),
243  'group' => 'default',
244  'desc' => __( 'Only allow access to this View when embedded using the shortcode.', 'gravityview' ),
245  'type' => 'checkbox',
246  'value' => '',
247  'tooltip' => false,
248  'show_in_shortcode' => false,
249  'full_width' => true,
250  ),
251  ), ( gravityview()->plugin->supports( Plugin::FEATURE_REST ) && ( gravityview()->plugin->settings->get( 'rest_api' ) === '1' ) ) ?
252  array(
253  'rest_disable' => array(
254  'label' => __( 'Prevent REST Access', 'gravityview' ),
255  'group' => 'default',
256  'desc' => __( 'Disable REST access to this View.', 'gravityview' ),
257  'type' => 'checkbox',
258  'value' => '',
259  'tooltip' => false,
260  'show_in_shortcode' => false,
261  'full_width' => true,
262  ),
263  ) : array(),
264  ( gravityview()->plugin->supports( Plugin::FEATURE_REST ) && ( gravityview()->plugin->settings->get( 'rest_api' ) !== '1' ) ) ?
265  array(
266  'rest_enable' => array(
267  'label' => __( 'Allow REST Access', 'gravityview' ),
268  'group' => 'default',
269  'desc' => __( 'Enable REST access to this View.', 'gravityview' ),
270  'type' => 'checkbox',
271  'value' => '',
272  'tooltip' => false,
273  'show_in_shortcode' => false,
274  'full_width' => true,
275  ),
276  ) : array(),
277  array(
278  'csv_enable' => array(
279  'label' => __( 'Allow CSV Access', 'gravityview' ),
280  'group' => 'default',
281  'desc' => __( 'Enable CSV access to this View.', 'gravityview' ),
282  'type' => 'checkbox',
283  'value' => '',
284  'tooltip' => false,
285  'show_in_shortcode' => false,
286  'full_width' => true,
287  ),
288  ),
289  array(
290  'post_id' => array(
291  'type' => 'number',
292  'value' => '',
293  'show_in_shortcode' => false,
294  ),
295  ) );
296 
297  if ( version_compare( \GFCommon::$version, '2.3-beta-4', '>=' ) ) {
298  $default_settings['sort_direction']['options']['RAND'] = __( 'Random', 'gravityview' );
299  }
300 
301  /**
302  * @filter `gravityview_default_args` Modify the default settings for new Views
303  * @param[in,out] array $default_args Array of default args.
304  * @deprecated
305  * @see filter `gravityview/view/settings/defaults`
306  */
307  $default_settings = apply_filters( 'gravityview_default_args', $default_settings );
308 
309  /**
310  * @filter `gravityview/view/defaults` Modify the default settings for new Views
311  * @param[in,out] array $default_settings Array of default settings.
312  */
313  $default_settings = apply_filters( 'gravityview/view/settings/defaults', $default_settings );
314 
315  // By default, we only want the key => value pairing, not the whole array.
316  if ( ! $detailed ) {
317  $defaults = array();
318  foreach( $default_settings as $key => $value ) {
319  $defaults[ $key ] = $value['value'];
320  }
321  return $defaults;
322 
323  // But sometimes, we want all the details.
324  } else {
325  foreach ( $default_settings as $key => $value ) {
326 
327  // If the $group argument is set for the method,
328  // ignore any settings that aren't in that group.
329  if ( ! empty( $group ) && is_string( $group ) ) {
330  if ( empty( $value['group'] ) || $value['group'] !== $group ) {
331  unset( $default_settings[ $key ] );
332  }
333  }
334  }
335  return $default_settings;
336  }
337  }
338 
339  /**
340  * Turn to an $atts array as used around the old codebase.
341  *
342  * @internal
343  * @deprecated
344  *
345  * @return array
346  */
347  public function as_atts() {
348  $defaults = array_keys( self::defaults() );
349  $_this = &$this;
350  return array_combine( $defaults, array_map( function( $key ) use ( $_this ) {
351  return $_this->get( $key );
352  }, $defaults ) );
353  }
354 }
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.
as_atts()
Turn to an $atts array as used around the old codebase.
static defaults( $detailed=false, $group=null)
Retrieve the default View settings.