GravityView  1.22.6
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  /**
15  * Retrieve the default View settings.
16  *
17  * @param bool $detailed Whether to return detailed setting meta information or just the value.
18  * @param string $group Retrieve settings of a particular group.
19  *
20  * @api
21  * @since future
22  *
23  * @return array The default settings along with their values.
24  * @param[out] string $label Setting label shown in admin
25  * @param[out] string $type Gravity Forms field type
26  * @param[out] string $group The field group the setting is associated with. Default: "default"
27  * @param[out] mixed $value The default value for the setting
28  * @param[out] string $tooltip Tooltip displayed for the setting
29  * @param[out] boolean $show_in_shortcode Whether to show the setting in the shortcode configuration modal
30  * @param[out] array $options Array of values to use when generating select, multiselect, radio, or checkboxes fields
31  * @param[out] boolean $full_width True: Display the input and label together when rendering. False: Display label and input in separate columns when rendering.
32  */
33  public static function defaults( $detailed = false, $group = null ) {
34 
35  $default_settings = array(
36  'id' => array(
37  'label' => __('View ID', 'gravityview'),
38  'type' => 'number',
39  'group' => 'default',
40  'value' => NULL,
41  'tooltip' => NULL,
42  'show_in_shortcode' => false,
43  ),
44  'page_size' => array(
45  'label' => __('Number of entries per page', 'gravityview'),
46  'type' => 'number',
47  'class' => 'small-text',
48  'group' => 'default',
49  'value' => 25,
50  'show_in_shortcode' => true,
51  ),
52  'offset' => array(
53  'label' => __('Offset entries starting from', 'gravityview'),
54  'type' => 'number',
55  'class' => 'small-text',
56  'group' => 'default',
57  'value' => 0,
58  'show_in_shortcode' => true,
59  ),
60  'lightbox' => array(
61  'label' => __( 'Enable lightbox for images', 'gravityview' ),
62  'type' => 'checkbox',
63  'group' => 'default',
64  'value' => 1,
65  'tooltip' => NULL,
66  'show_in_shortcode' => true,
67  ),
68  'show_only_approved' => array(
69  'label' => __( 'Show only approved entries', 'gravityview' ),
70  'type' => 'checkbox',
71  'group' => 'default',
72  'value' => 0,
73  'show_in_shortcode' => true,
74  ),
75  'admin_show_all_statuses' => array(
76  'label' => __( 'Show all entries to administrators', 'gravityview' ),
77  'desc' => __('Administrators will be able to see entries with any approval status.', 'gravityview'),
78  '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'),
79  'requires' => 'show_only_approved',
80  'type' => 'checkbox',
81  'group' => 'default',
82  'value' => 0,
83  'show_in_shortcode' => false,
84  ),
85  'hide_until_searched' => array(
86  'label' => __( 'Hide View data until search is performed', 'gravityview' ),
87  'type' => 'checkbox',
88  'group' => 'default',
89  'tooltip' => __( 'When enabled it will only show any View entries after a search is performed.', 'gravityview' ),
90  'value' => 0,
91  'show_in_shortcode' => false,
92  ),
93  'hide_empty' => array(
94  'label' => __( 'Hide empty fields', 'gravityview' ),
95  'group' => 'default',
96  'type' => 'checkbox',
97  'value' => 1,
98  'show_in_shortcode' => false,
99  ),
100  'user_edit' => array(
101  'label' => __( 'Allow User Edit', 'gravityview' ),
102  'group' => 'default',
103  'desc' => __('Allow logged-in users to edit entries they created.', 'gravityview'),
104  'value' => 0,
105  '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'),
106  'type' => 'checkbox',
107  'show_in_shortcode' => true,
108  ),
109  'user_delete' => array(
110  'label' => __( 'Allow User Delete', 'gravityview' ),
111  'group' => 'default',
112  'desc' => __('Allow logged-in users to delete entries they created.', 'gravityview'),
113  'value' => 0,
114  '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'),
115  'type' => 'checkbox',
116  'show_in_shortcode' => true,
117  ),
118  'sort_field' => array(
119  'label' => __('Sort by field', 'gravityview'),
120  'type' => 'select',
121  'value' => '',
122  'group' => 'sort',
123  'options' => array(
124  '' => __( 'Default', 'gravityview'),
125  'date_created' => __( 'Date Created', 'gravityview'),
126  ),
127  'show_in_shortcode' => true,
128  ),
129  'sort_direction' => array(
130  'label' => __('Sort direction', 'gravityview'),
131  'type' => 'select',
132  'value' => 'ASC',
133  'group' => 'sort',
134  'options' => array(
135  'ASC' => __('ASC', 'gravityview'),
136  'DESC' => __('DESC', 'gravityview'),
137  ),
138  'show_in_shortcode' => true,
139  ),
140  'sort_columns' => array(
141  'label' => __( 'Enable sorting by column', 'gravityview' ),
142  'left_label' => __( 'Column Sorting', 'gravityview' ),
143  'type' => 'checkbox',
144  'value' => false,
145  'group' => 'sort',
146  'tooltip' => NULL,
147  'show_in_shortcode' => true,
148  'show_in_template' => array( 'default_table', 'preset_business_data', 'preset_issue_tracker', 'preset_resume_board', 'preset_job_board' ),
149  ),
150  'start_date' => array(
151  'label' => __('Filter by Start Date', 'gravityview'),
152  'class' => 'gv-datepicker',
153  'desc' => __('Show entries submitted after this date. Supports relative dates, such as "-1 week" or "-1 month".', 'gravityview' ),
154  'type' => 'text',
155  'value' => '',
156  'group' => 'filter',
157  'show_in_shortcode' => true,
158  ),
159  'end_date' => array(
160  'label' => __('Filter by End Date', 'gravityview'),
161  'class' => 'gv-datepicker',
162  'desc' => __('Show entries submitted before this date. Supports relative dates, such as "now" or "-3 days".', 'gravityview' ),
163  'type' => 'text',
164  'value' => '',
165  'group' => 'filter',
166  'show_in_shortcode' => true,
167  ),
168  'class' => array(
169  'label' => __('CSS Class', 'gravityview'),
170  'desc' => __('CSS class to add to the wrapping HTML container.', 'gravityview'),
171  'group' => 'default',
172  'type' => 'text',
173  'value' => '',
174  'show_in_shortcode' => false,
175  ),
176  'search_value' => array(
177  'label' => __('Search Value', 'gravityview'),
178  'desc' => __('Define a default search value for the View', 'gravityview'),
179  'type' => 'text',
180  'value' => '',
181  'group' => 'filter',
182  'show_in_shortcode' => false,
183  ),
184  'search_field' => array(
185  'label' => __('Search Field', 'gravityview'),
186  'desc' => __('If Search Value is set, you can define a specific field to search in. Otherwise, all fields will be searched.', 'gravityview'),
187  'type' => 'number',
188  'value' => '',
189  'group' => 'filter',
190  'show_in_shortcode' => false,
191  ),
192  'single_title' => array(
193  'label' => __('Single Entry Title', 'gravityview'),
194  'type' => 'text',
195  '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'),
196  'group' => 'default',
197  'value' => '',
198  'show_in_shortcode' => false,
199  'full_width' => true,
200  ),
201  'back_link_label' => array(
202  'label' => __('Back Link Label', 'gravityview'),
203  'group' => 'default',
204  'desc' => __('The text of the link that returns to the multiple entries view.', 'gravityview'),
205  'type' => 'text',
206  'value' => '',
207  'show_in_shortcode' => false,
208  'full_width' => true,
209  ),
210  'embed_only' => array(
211  'label' => __('Prevent Direct Access', 'gravityview'),
212  'group' => 'default',
213  'desc' => __('Only allow access to this View when embedded using the shortcode.', 'gravityview'),
214  'type' => 'checkbox',
215  'value' => '',
216  'tooltip' => false,
217  'show_in_shortcode' => false,
218  'full_width' => true,
219  ),
220  'post_id' => array(
221  'type' => 'number',
222  'value' => '',
223  'show_in_shortcode' => false,
224  ),
225  );
226 
227  if ( version_compare( \GFCommon::$version, '2.3-beta-4', '>=' ) ) {
228  $default_settings['sort_direction']['options']['RAND'] = __( 'Random', 'gravityview' );
229  }
230 
231  /**
232  * @filter `gravityview_default_args` Modify the default settings for new Views
233  * @param[in,out] array $default_args Array of default args.
234  * @deprecated
235  * @see filter `gravityview/view/settings/defaults`
236  */
237  $default_settings = apply_filters( 'gravityview_default_args', $default_settings );
238 
239  /**
240  * @filter `gravityview/view/defaults` Modify the default settings for new Views
241  * @param[in,out] array $default_settings Array of default settings.
242  */
243  $default_settings = apply_filters( 'gravityview/view/settings/defaults', $default_settings );
244 
245  // By default, we only want the key => value pairing, not the whole array.
246  if ( ! $detailed ) {
247  $defaults = array();
248  foreach( $default_settings as $key => $value ) {
249  $defaults[ $key ] = $value['value'];
250  }
251  return $defaults;
252 
253  // But sometimes, we want all the details.
254  } else {
255  foreach ($default_settings as $key => $value) {
256 
257  // If the $group argument is set for the method,
258  // ignore any settings that aren't in that group.
259  if ( ! empty( $group ) && is_string( $group ) ) {
260  if ( empty( $value['group'] ) || $value['group'] !== $group ) {
261  unset( $default_settings[ $key ] );
262  }
263  }
264  }
265  return $default_settings;
266  }
267  }
268 
269  /**
270  * Mass update values from the allowed ones.
271  *
272  * @api
273  * @since future
274  *
275  * @param array An array of settings to update.
276  * @return void
277  */
278  public function update( $settings ) {
279  foreach ( $settings as $key => $value ) {
280  $this->set( $key, $value );
281  }
282  }
283 
284  /**
285  * Turn to an $atts array as used around the old codebase.
286  *
287  * @internal
288  * @deprecated
289  *
290  * @return array
291  */
292  public function as_atts() {
293  $defaults = array_keys( self::defaults() );
294  $_this = &$this;
295  return array_combine( $defaults, array_map( function( $key ) use ( $_this ) {
296  return $_this->get( $key );
297  }, $defaults ) );
298  }
299 }
If this file is called directly, abort.
update( $settings)
Mass update values from the allowed ones.
If this file is called directly, abort.
as_atts()
Turn to an $atts array as used around the old codebase.
static defaults( $detailed=false, $group=null)
Retrieve the default View settings.