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 Entry List Template class . |
11
|
|
|
* |
12
|
|
|
* Renders a \GV\Entry using a \GV\Entry_Renderer. |
13
|
|
|
*/ |
14
|
|
|
class Entry_List_Template extends Entry_Template { |
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 array $extras Extra stuff, like wpautop, etc. |
25
|
|
|
* |
26
|
|
|
* @return string |
27
|
|
|
*/ |
28
|
2 |
|
public function the_field( \GV\Field $field, $extras = null ) { |
29
|
2 |
|
$form = \GV\GF_Form::by_id( $field->form_id ) ? : $this->view->form; |
|
|
|
|
30
|
2 |
|
$entry = $this->entry->from_field( $field ); |
31
|
|
|
|
32
|
2 |
|
if ( ! $entry ) { |
33
|
|
|
return ''; |
34
|
|
|
} |
35
|
|
|
|
36
|
2 |
|
$renderer = new Field_Renderer(); |
37
|
2 |
|
$source = is_numeric( $field->ID ) ? ( GF_Form::by_id( $field->form_id ) ? : $this->view->form ) : new Internal_Source(); |
|
|
|
|
38
|
|
|
|
39
|
2 |
|
$value = $renderer->render( $field, $this->view, $source, $entry, $this->request ); |
40
|
|
|
|
41
|
2 |
|
$context = Template_Context::from_template( $this, compact( 'field', 'entry' ) ); |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @deprecated Here for back-compatibility. |
45
|
|
|
*/ |
46
|
2 |
|
$label = apply_filters( 'gravityview_render_after_label', $field->get_label( $this->view, $form, $entry ), $field->as_configuration() ); |
47
|
2 |
|
$label = apply_filters( 'gravityview/template/field_label', $label, $field->as_configuration(), is_numeric( $field->ID ) ? ( $source->form ? $source->form : null ) : null, $entry->as_entry() ); |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @filter `gravityview/template/field/label` Override the field label. |
51
|
|
|
* @since 2.0 |
52
|
|
|
* @param[in,out] string $label The label to override. |
53
|
|
|
* @param \GV\Template_Context $context The context. |
54
|
|
|
*/ |
55
|
2 |
|
$label = apply_filters( 'gravityview/template/field/label', $label, $context ); |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @filter `gravityview/template/table/entry/hide_empty` |
59
|
|
|
* @param boolean $hide_empty Should the row be hidden if the value is empty? Default: don't hide. |
60
|
|
|
* @param \GV\Template_Context $context The context ;) Love it, cherish it. And don't you dare modify it! |
61
|
|
|
*/ |
62
|
2 |
|
$hide_empty = apply_filters( 'gravityview/render/hide-empty-zone', Utils::get( $extras, 'hide_empty', $this->view->settings->get( 'hide_empty', false ) ), $context ); |
63
|
|
|
|
64
|
2 |
|
if ( is_numeric( $field->ID ) ) { |
65
|
2 |
|
$extras['field'] = $field->as_configuration(); |
66
|
|
|
} |
67
|
|
|
|
68
|
2 |
|
$extras['entry'] = $this->entry->as_entry(); |
69
|
2 |
|
$extras['hide_empty'] = $hide_empty; |
70
|
2 |
|
$extras['label'] = $label; |
71
|
2 |
|
$extras['value'] = $value; |
72
|
|
|
|
73
|
2 |
|
return \gravityview_field_output( $extras, $context ); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Return an array of variables ready to be extracted. |
78
|
|
|
* |
79
|
|
|
* @param string|array $zones The field zones to grab. |
80
|
|
|
* |
81
|
|
|
* @return array An array ready to be extract()ed in the form of |
82
|
|
|
* $zone => \GV\Field_Collection |
83
|
|
|
* has_$zone => int |
84
|
|
|
*/ |
85
|
2 |
|
public function extract_zone_vars( $zones ) { |
86
|
2 |
|
if ( ! is_array( $zones ) ) { |
87
|
|
|
$zones = array( $zones ); |
88
|
|
|
} |
89
|
|
|
|
90
|
2 |
|
$vars = array(); |
91
|
2 |
|
foreach ( $zones as $zone ) { |
92
|
2 |
|
$zone_var = str_replace( '-', '_', $zone ); |
93
|
2 |
|
$vars[ $zone_var ] = $this->view->fields->by_position( 'single_list-' . $zone )->by_visible( $this->view ); |
94
|
2 |
|
$vars[ "has_$zone_var" ] = $vars[ $zone_var ]->count(); |
95
|
|
|
} |
96
|
|
|
|
97
|
2 |
|
return $vars; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.