1 | <?php |
||
14 | class View_List_Template extends View_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 \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 | */ |
||
50 | \GV\Mocks\Legacy_Context::load( array( |
||
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[in,out] 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 | 1 | public static function body_before( $context ) { |
|
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 | 1 | public static function body_after( $context ) { |
|
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 = '' ) { |
||
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 = '' ) { |
||
271 | } |
||
272 |
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.