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