GravityView  2.1.1
The best, easiest way to display Gravity Forms entries on your website.
class-gv-template-view-list.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 List Template class .
11  *
12  * Renders a \GV\View and a \GV\Entry_Collection via a \GV\View_Renderer.
13  */
15  /**
16  * @var string The template slug to be loaded (like "table", "list")
17  */
18  public static $slug = 'list';
19 
20  /**
21  * Output the field in the list view.
22  *
23  * @param \GV\Field $field The field to output.
24  * @param \GV\Entry $entry The entry.
25  * @param array $extras Extra stuff, like wpautop, etc.
26  *
27  * @return string
28  */
29  public function the_field( \GV\Field $field, \GV\Entry $entry, $extras = null ) {
30  $form = $this->view->form;
31 
32  /**
33  * Push legacy entry context.
34  */
36  'entry' => $entry,
37  ) );
38 
39  if ( $entry instanceof Multi_Entry ) {
40  if ( ! $entry = Utils::get( $entry, $field->form_id ) ) {
41  return;
42  }
43  $form = GF_Form::by_id( $field->form_id );
44  }
45 
46  $context = Template_Context::from_template( $this, compact( 'field', 'entry' ) );
47 
48  $renderer = new Field_Renderer();
49  $source = is_numeric( $field->ID ) ? $form : new Internal_Source();
50 
51  $value = $renderer->render( $field, $this->view, $source, $entry, $this->request );
52 
53  /**
54  * @deprecated Here for back-compatibility.
55  */
56  $label = apply_filters( 'gravityview_render_after_label', $field->get_label( $this->view, $form ), $field->as_configuration() );
57  $label = apply_filters( 'gravityview/template/field_label', $label, $field->as_configuration(), $form->form ? $form->form : null, null );
58 
59  /**
60  * @filter `gravityview/template/field/label` Override the field label.
61  * @since 2.0
62  * @param[in,out] string $label The label to override.
63  * @param \GV\Template_Context $context The context.
64  */
65  $label = apply_filters( 'gravityview/template/field/label', $label, $context );
66 
67  /**
68  * @filter `gravityview/template/table/entry/hide_empty`
69  * @param boolean Should the row be hidden if the value is empty? Default: don't hide.
70  * @param \GV\Template_Context $context The context ;) Love it, cherish it. And don't you dare modify it!
71  */
72  $hide_empty = apply_filters( 'gravityview/render/hide-empty-zone', Utils::get( $extras, 'hide_empty', $this->view->settings->get( 'hide_empty', false ) ), $context );
73 
74  if ( is_numeric( $field->ID ) ) {
75  $extras['field'] = $field->as_configuration();
76  }
77 
78  $extras['entry'] = $entry->as_entry();
79  $extras['hide_empty'] = $hide_empty;
80  $extras['label'] = $label;
81  $extras['value'] = $value;
82 
83  return \gravityview_field_output( $extras, $context );
84  }
85 
86  /**
87  * Return an array of variables ready to be extracted.
88  *
89  * @param string|array $zones The field zones to grab.
90  *
91  * @return array An array ready to be extract()ed in the form of
92  * $zone => \GV\Field_Collection
93  * has_$zone => int
94  */
95  public function extract_zone_vars( $zones ) {
96  if ( ! is_array( $zones ) ) {
97  $zones = array( $zones );
98  }
99 
100  $vars = array();
101  foreach ( $zones as $zone ) {
102  $zone_var = str_replace( '-', '_', $zone );
103  $vars[ $zone_var ] = $this->view->fields->by_position( 'directory_list-' . $zone )->by_visible();
104  $vars[ "has_$zone_var" ] = $vars[ $zone_var ]->count();
105  }
106 
107  return $vars;
108  }
109 
110  /**
111  * `gravityview_entry_class` and `gravityview/template/list/entry/class` filters.
112  *
113  * Modify of the class of a row.
114  *
115  * @param string $class The class.
116  * @param \GV\Entry $entry The entry.
117  * @param \GV\Template_Context The context.
118  *
119  * @return string The classes.
120  */
121  public static function entry_class( $class, $entry, $context ) {
122  /**
123  * @filter `gravityview_entry_class` Modify the class applied to the entry row.
124  * @param string $class Existing class.
125  * @param array $entry Current entry being displayed
126  * @param \GravityView_View $this Current GravityView_View object
127  * @deprecated Use `gravityview/template/list/entry/class`
128  * @return string The modified class.
129  */
130  $class = apply_filters( 'gravityview_entry_class', $class, $entry->as_entry(), \GravityView_View::getInstance() );
131 
132  /**
133  * @filter `gravityview/template/list/entry/class` Modify the class aplied to the entry row.
134  * @param string $class The existing class.
135  * @param \GV\Template_Context The context.
136  * @return string The modified class.
137  */
138  return apply_filters( 'gravityview/template/list/entry/class', $class, Template_Context::from_template( $context->template, compact( 'entry' ) ) );
139  }
140 
141  /**
142  * `gravityview_list_body_before` and `gravityview/template/list/body/before` actions.
143  *
144  * Output inside the `tbody` of the list.
145  *
146  * @param $context \GV\Template_Context The 2.0 context.
147  *
148  * @return void
149  */
150  public static function body_before( $context ) {
151  /**
152  * @action `gravityview/template/list/body/before` Output inside the `tbody` of the list.
153  * @since 2.0
154  * @param \GV\Template_Context $context The template context.
155  */
156  do_action( 'gravityview/template/list/body/before', $context );
157 
158  /**
159  * @action `gravityview_list_body_before` Inside the `tbody`, before any rows are rendered. Can be used to insert additional rows.
160  * @deprecated Use `gravityview/template/list/body/before`
161  * @since 1.0.7
162  * @param \GravityView_View $gravityview_view Current GravityView_View object.
163  */
164  do_action( 'gravityview_list_body_before', \GravityView_View::getInstance() /** ugh! */ );
165  }
166 
167  /**
168  * `gravityview_list_body_after` and `gravityview/template/list/body/after` actions.
169  *
170  * Output inside the `tbody` of the list.
171  *
172  * @param $context \GV\Template_Context The 2.0 context.
173  *
174  * @return void
175  */
176  public static function body_after( $context ) {
177  /**
178  * @action `gravityview/template/list/body/after` Output inside the `tbody` of the list at the end.
179  * @since 2.0
180  * @param \GV\Template_Context $context The template context.
181  */
182  do_action( 'gravityview/template/list/body/after', $context );
183 
184  /**
185  * @action `gravityview_list_body_after` Inside the `tbody`, after any rows are rendered. Can be used to insert additional rows.
186  * @deprecated Use `gravityview/template/list/body/after`
187  * @since 1.0.7
188  * @param \GravityView_View $gravityview_view Current GravityView_View object.
189  */
190  do_action( 'gravityview_list_body_after', \GravityView_View::getInstance() /** ugh! */ );
191  }
192 
193  /**
194  * `gravityview_list_entry_before` and `gravityview/template/list/entry/before` actions.
195  * `gravityview_list_entry_title_before` and `gravityview/template/list/entry/title/before` actions.
196  * `gravityview_list_entry_content_before` and `gravityview/template/list/entry/content/before` actions.
197  * `gravityview_list_entry_footer_before` and `gravityview/template/list/entry/footer/before` actions.
198  *
199  * Output inside the `entry` of the list.
200  *
201  * @param \GV\Entry $entry The entry.
202  * @param \GV\Template_Context $context The 2.0 context.
203  * @param string $zone The list zone (footer, image, title, etc.).
204  *
205  * @return void
206  */
207  public static function entry_before( $entry, $context, $zone = '' ) {
208  $zone = str_replace( '//', '/', "/$zone/" );
209 
210  /**
211  * @action `gravityview/template/list/entry/$zone/before` Output inside the `entry` of the list at the end.
212  * @since 2.0
213  * @param \GV\Template_Context $context The template context.
214  */
215  do_action( sprintf( 'gravityview/template/list/entry%sbefore', $zone ), Template_Context::from_template( $context->template, compact( 'entry' ) ) );
216 
217  $zone = str_replace( '/', '_', $zone );
218 
219  /**
220  * @action `gravityview_list_entry_$zone_before` Inside the `entry`, before any rows are rendered. Can be used to insert additional rows.
221  * @deprecated Use `gravityview/template/list/entry/$zone/before`
222  * @since 1.0.7
223  * @param \GravityView_View $gravityview_view Current GravityView_View object.
224  */
225  do_action( sprintf( 'gravityview_list_entry%sbefore', $zone ), $entry->as_entry(), \GravityView_View::getInstance() /** ugh! */ );
226  }
227 
228  /**
229  * `gravityview_list_entry_after` and `gravityview/template/list/entry/after` actions.
230  * `gravityview_list_entry_title_after` and `gravityview/template/list/entry/title/after` actions.
231  * `gravityview_list_entry_content_after` and `gravityview/template/list/entry/content/after` actions.
232  * `gravityview_list_entry_footer_after` and `gravityview/template/list/entry/footer/after` actions.
233  *
234  * Output inside the `entry` of the list.
235  *
236  * @param \GV\Entry $entry The entry.
237  * @param \GV\Template_Context $context The 2.0 context.
238  * @param string $zone The list zone (footer, image, title, etc.).
239  *
240  * @return void
241  */
242  public static function entry_after( $entry, $context, $zone = '' ) {
243  $zone = str_replace( '//', '/', "/$zone/" );
244 
245  /**
246  * @action `gravityview/template/list/entry/$zone/after` Output inside the `entry` of the list at the end.
247  * @since 2.0
248  * @param \GV\Template_Context $context The template context.
249  */
250  do_action( sprintf( 'gravityview/template/list/entry%safter', $zone ), Template_Context::from_template( $context->template, compact( 'entry' ) ) );
251 
252  $zone = str_replace( '/', '_', $zone );
253 
254  /**
255  * @action `gravityview_list_entry_$zone_after` Inside the `entry`, after any rows are rendered. Can be used to insert additional rows.
256  * @deprecated Use `gravityview/template/list/entry/after`
257  * @since 1.0.7
258  * @param \GravityView_View $gravityview_view Current GravityView_View object.
259  */
260  do_action( sprintf( 'gravityview_list_entry%safter', $zone ), $entry->as_entry(), \GravityView_View::getInstance() /** ugh! */ );
261  }
262 }
the_field(\GV\Field $field, \GV\Entry $entry, $extras=null)
Output the field in the list view.
static body_before( $context)
gravityview_list_body_before and gravityview/template/list/body/before actions.
static getInstance( $passed_post=NULL)
$class
If this file is called directly, abort.
static entry_after( $entry, $context, $zone='')
gravityview_list_entry_after and gravityview/template/list/entry/after actions.
get( $key, $default=null)
Retrieve a setting.
static load( $configuration)
Hydrates the legacy context globals as needed.
Definition: _mocks.php:546
static body_after( $context)
gravityview_list_body_after and gravityview/template/list/body/after actions.
If this file is called directly, abort.
If this file is called directly, abort.
If this file is called directly, abort.
If this file is called directly, abort.
static entry_before( $entry, $context, $zone='')
gravityview_list_entry_before and gravityview/template/list/entry/before actions. ...
extract_zone_vars( $zones)
Return an array of variables ready to be extracted.
If this file is called directly, abort.
static entry_class( $class, $entry, $context)
gravityview_entry_class and gravityview/template/list/entry/class filters.
If this file is called directly, abort.
gravityview_field_output( $passed_args, $context=null)
Output field based on a certain html markup.
Definition: class-api.php:1272
$entry
Definition: notes.php:27
$field
Definition: gquiz_grade.php:11