-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate-detail-hulpmiddelen.php
490 lines (399 loc) · 18.1 KB
/
template-detail-hulpmiddelen.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
<?php
/**
* Template Name: [Hulpmiddel] detailpagina
*
* @package WordPress
* @subpackage Timber v2
*/
$timber_post = Timber::get_post();
$current_hulpmiddel_taxid = get_current_hulpmiddel_tax();
$current_hulpmiddel_term = get_term_by( 'id', $current_hulpmiddel_taxid, GC_HULPMIDDEL_TAX );
$context = Timber::context();
$context['post'] = $timber_post;
$context['modifier'] = 'hulpmiddel-detail';
$context['is_unboxed'] = true;
$context['show_author'] = false;
if ( $current_hulpmiddel_term && ! is_wp_error( $current_hulpmiddel_term ) ) {
// Update body class
$context['body_class'] = ( $context['body_class'] ?: '' ) . ' single-hulpmiddel hulpmiddel--' . $current_hulpmiddel_term->slug;
}
$templates = [ 'hulpmiddel-detail.twig', 'page.twig' ];
/**
* returns the ID for the hulpmiddel term that is
* attached to this page in ACF field 'hulpmiddel_detail_select_hulpmiddel_term'
*
* @return int
*/
function get_current_hulpmiddel_tax() {
global $post;
$term_id = get_field( 'hulpmiddel_detail_select_hulpmiddel_term' ) ?: 0;
if ( ! $term_id ) {
$aargh = _x( 'Geen hulpmiddel gekoppeld aan deze pagina. ', 'Hulpmiddel taxonomy error message', 'gctheme' );
if ( current_user_can( 'editor' ) ) {
$editlink = get_edit_post_link( $post );
$aargh .= '<a href="' . $editlink . '">' . _x( 'Kies een relevante hulpmiddel voor deze pagina. ', 'Hulpmiddel taxonomy error message', 'gctheme' ) . '</a>';
}
die( $aargh );
}
return $term_id;
}
/**
* Fill Timber $context with available page/post Blocks/Metaboxes
* @see /includes/gc-fill-context-with-acf-fields.php
*/
if ( function_exists( 'gc_fill_context_with_acf_fields' ) ) {
$context = gc_fill_context_with_acf_fields( $context );
}
// We have a valid Hulpmiddel Term for this page
if ( $current_hulpmiddel_term && ! is_wp_error( $current_hulpmiddel_term ) ) {
// Get custom ACF fields for this WP_Term..
// filter out 'empty' or nullish values
$current_hulpmiddel_term_fields = array_filter(
get_fields( $current_hulpmiddel_term ) ?: [],
function ( $field ) {
return ! empty( $field );
}
);
if ( $current_hulpmiddel_term_fields ) {
// We have some custom ACF fields for this Term
// If we have a palette:
if ( isset( $current_hulpmiddel_term_fields['hulpmiddel_taxonomy_colorscheme'] ) ) {
// .. store it in $context
$context['palette'] = $current_hulpmiddel_term_fields['hulpmiddel_taxonomy_colorscheme'];
// .. update body class
$context['body_class'] = ( $context['body_class'] ?: '' ) . ' palette--' . $context['palette'];
}
// If we have a visual, store it in $context
if ( isset( $current_hulpmiddel_term_fields['hulpmiddel_taxonomy_visual'] ) ) {
// Store complete Path to image (if available)
$context['visual'] = sprintf( '%s/%s', GC_HULPMIDDEL_TAX_VISUALS_PATH, $current_hulpmiddel_term_fields['hulpmiddel_taxonomy_visual'] );
}
// If we have an extra Hulpmiddel Link
if ( isset( $current_hulpmiddel_term_fields['hulpmiddel_taxonomy_link'] ) ) {
$context['hulpmiddel_link'] = $current_hulpmiddel_term_fields['hulpmiddel_taxonomy_link'];
}
}
// Fallback: Term VISUAL
// if ( ! array_key_exists( 'visual', $context ) ) {
// $context['visual'] = sprintf( '%s/', GC_HULPMIDDEL_TAX_VISUALS_PATH ) . 'default.svg';
// }
// // Fallback: Term COLORSCHEME
// if ( ! array_key_exists( 'palette', $context ) && function_exists( 'gc_get_colorschemes' ) ) {
// $available_color_themes = gc_get_colorschemes();
// $context['palette'] = $available_color_themes ? reset( $available_color_themes ) : 'green';
// }
// CONTENT
// -----------------------------
// text for 'inleiding' is taken from term description
// -----------------------------
// $timber_post->post_content = $current_hulpmiddel_term->description;
// Use Excerpt instead?! Fall back to Term description if no Excerpt is set?
if ( empty( $context['intro'] ) ) {
$context['intro'] = wpautop( $current_hulpmiddel_term->description );
}
/**
* (10) Intro Text (Metabox)
* ----------------------------- */
$metabox_intro_text = get_field( 'metabox_intro_text' );
if ( ! empty( $metabox_intro_text ) ) {
$context['metabox_intro_text'] = $metabox_intro_text;
}
// /**
// * (20) Infoblokken (USP)
// * ----------------------------- */
// $metabox_fields = get_field( 'icoonblokken' );
// if ( ! empty( $metabox_fields ) ) {
// if ( $metabox_fields && 'ja' === $metabox_fields['metabox_icoonblokken_show_or_not'] ) {
// $metabox_fields_items = $metabox_fields['metabox_icoonblokken_items'];
// foreach ( $metabox_fields_items as $block ) {
// $item = array();
// if ( isset( $block['title'] ) && $block['title'] && isset( $block['description'] ) && $block['description'] ) {
// $item['modifier'] = $block['icon'];
// $item['title'] = $block['title'];
// $item['content'] = wpautop( $block['description'] );
// $context['metabox_icoonblokken']['items'][] = $item;
// }
// }
// }
// }
// /**
// * (30) Events box
// * ----------------------------- */
// // Only show events if Events Manager plugin is active
// if ( class_exists( 'EM_Events' ) ) {
// // the events manager is active, which helps for selecting events
// $metabox_fields = get_field( 'events' );
// if ( $metabox_fields && 'ja' === $metabox_fields['metabox_events_show_or_not'] ) {
// $method = $metabox_fields['metabox_events_selection_method'] ?? '';
// $maxnr = $metabox_fields['metabox_events_max_nr'] ?? 3;
// $metabox_item_ids = array();
// if ( 'manual' === $method ) {
// // manually selected events, returns an array of events
// $metabox_item_ids = $metabox_fields['metabox_events_selection_manual'];
// } else {
// // select latest events for $current_hulpmiddel_taxid
// // _event_start_date is a meta field for the events post type
// // this query selects future events for the $current_hulpmiddel_taxid
// $currentdate = date( "Y-m-d" );
// $args = array(
// 'posts_per_page' => $maxnr,
// 'post_type' => EM_POST_TYPE_EVENT,
// 'meta_key' => '_event_start_date',
// 'orderby' => 'meta_value',
// 'post_status' => 'publish',
// 'order' => 'ASC', // order by start date ascending
// 'fields' => 'ids', // only return IDs
// 'tax_query' => array(
// array(
// 'taxonomy' => GC_HULPMIDDEL_TAX,
// 'field' => 'term_id',
// 'terms' => $current_hulpmiddel_term->term_id,
// )
// ),
// 'meta_query' => array(
// array(
// 'key' => '_event_start_date',
// 'value' => $currentdate,
// 'compare' => '>=',
// 'type' => 'DATE',
// ),
// )
// );
// $query_items = new WP_Query( $args );
// if ( $query_items->have_posts() ) {
// // we only use post ids for the $metabox_item_ids array
// $metabox_item_ids = $query_items->posts;
// }
// // ensure to reset the main query to original main query
// wp_reset_query();
// }
// if ( $metabox_item_ids ) {
// // we have events
// $context['metabox_events'] = [];
// $context['metabox_events']['items'] = [];
// $context['metabox_events']['title'] = $metabox_fields['metabox_events_titel'] ?? '';
// $context['metabox_events']['descr'] = $metabox_fields['metabox_events_description'] ?? '';
// $url = $metabox_fields['metabox_events_url_overview'] ?? [];
// // Add CTA 'overzichtslink' as cta Array to metabox_events
// if ( $url && isset( $url['title'] ) && isset( $url['url'] ) ) {
// $context['metabox_events']['cta'] = [];
// $context['metabox_events']['cta']['title'] = $url['title'];
// $context['metabox_events']['cta']['url'] = $url['url'];
// }
// foreach ( $metabox_item_ids as $post_id ) {
// $item = prepare_card_content( get_post( $post_id ) );
// $context['metabox_events']['items'][] = $item;
// }
// $context['metabox_events']['columncounter'] = count( $context['metabox_events']['items'] );
// }
// }
// }
/**
* (40) Posts box
* ----------------------------- */
$metabox_fields = get_field( 'berichten' );
if ( $metabox_fields && 'ja' === $metabox_fields['metabox_posts_show_or_not'] ) {
$method = $metabox_fields['metabox_posts_selection_method'] ?? '';
$maxnr = 3; // todo TBD: should this be a user editable field?
$metabox_item_ids = array();
if ( 'manual' === $method ) {
// manually selected events, returns an array of posts
$metabox_item_ids = $metabox_fields['metabox_posts_selection_manual'];
} else {
// Do we have a Post Category?
if ( array_key_exists( 'metabox_posts_category', $metabox_fields ) ) {
$metabox_posts_category = $metabox_fields['metabox_posts_category'];
}
$args = array(
'posts_per_page' => $maxnr,
'post_type' => 'post',
'post_status' => 'publish',
'fields' => 'ids', // only return IDs
);
// If we have a post category, add it to the Tax query
if ( ! empty( $metabox_posts_category ) ) {
$args['tax_query'][] = array(
'taxonomy' => GC_HULPMIDDEL_ARCHIVE_TAX, // We query on thema taxonomy
'field' => 'term_id',
'terms' => $metabox_posts_category,
);
}
$query_items = new WP_Query( $args );
if ( $query_items->have_posts() ) {
// we only use post ids for the $metabox_item_ids array
$metabox_item_ids = $query_items->posts;
}
// ensure to reset the main query to original main query
wp_reset_query();
}
if ( $metabox_item_ids ) {
$context['metabox_posts'] = [];
$context['metabox_posts']['items'] = [];
$context['metabox_posts']['cta'] = [];
$context['metabox_posts']['title'] = $metabox_fields['metabox_posts_titel'] ?? '';
$context['metabox_posts']['description'] = $metabox_fields['metabox_posts_description'] ?? '';
$archive_link_method = $metabox_fields['metabox_posts_archive_selection'] ?? [];
// $archive_link_method can be:
// none : Geen link
// automatic : Automatische link naar taxonomie archief
// custom : Geheel eigen link
if ( ! empty( $archive_link_method ) && $archive_link_method !== 'none' ) {
// Automatic Archive Link:
if ( 'automatic' === $archive_link_method ) {
// Hulpmiddel does _not_ have an archive.
// Posts are either chosen manually or automatically based on some _other_ Taxonomy.
// (which is defined in GC_HULPMIDDEL_ARCHIVE_TAX)
// Therefore: we can only link automatically to the GC_HULPMIDDEL_ARCHIVE_TAX archive.
// Do we have a set Post Category at all?
if ( array_key_exists( 'metabox_posts_category', $metabox_fields ) ) {
$metabox_posts_category = $metabox_fields['metabox_posts_category'];
}
if ( ! empty( $metabox_posts_category ) && is_object( $metabox_posts_category ) ) {
// Try and get the Term Link
// If our GC_HULPMIDDEL_ARCHIVE_TAX = 'thema'
// we try and find the LLK themafilter URL for our link.
// Else we pick the default Term Link.
if ( 'thema' === GC_HULPMIDDEL_ARCHIVE_TAX ) {
// fall back to hardcoded URL if we have not found a LLK 'lees' page
$metabox_posts_category_link = '/lees-luister-en-kijk/lees/';
// Now try and find our LLK 'lees' page
// (Hardcode 'template-llk-posts.php' :-/)
$llk_archive_page_query = new WP_Query( array(
'post_type' => 'page',
'post_status' => 'publish',
'posts_per_page' => 1,
'fields' => 'ids',
'meta_query' => array(
array(
'key' => '_wp_page_template',
'value' => 'template-llk-posts.php',
),
)
) );
if ( $llk_archive_page_query->have_posts() ) {
// Found a match, try and get the permalink from our 1st (!) post match.
$metabox_posts_category_link = get_permalink( reset( $llk_archive_page_query->posts ) );
}
// ensure to reset the main query to original main query
wp_reset_query();
// We should have an URL now. Now append the themafilter queryvar
$metabox_posts_category_link .= '?themafilter=' . $metabox_posts_category->slug;
} else {
$metabox_posts_category_link = get_term_link( (int) $metabox_posts_category->term_id, GC_HULPMIDDEL_ARCHIVE_TAX );
}
if ( $metabox_posts_category_link && ! is_wp_error( $metabox_posts_category_link ) ) {
$metabox_posts_category_text = $metabox_fields['metabox_posts_archive_selection_automatic_link_text'] ?: _x( 'Bekijk alle berichten', 'Linktekst voor Hulpmiddel berichten', 'gctheme' );
$metabox_posts_category_text = sprintf( $metabox_posts_category_text, '"' . $metabox_posts_category->name . '"' );
$context['metabox_posts']['cta']['title'] = $metabox_posts_category_text;
$context['metabox_posts']['cta']['url'] = $metabox_posts_category_link;
}
} else {
// We have NO Post Category
// So we can NOT automatically link to a Post Category archive..
// ...
}
}
// Custom Archive Link:
if ( 'custom' === $archive_link_method ) {
$custom_archive_link = $metabox_fields['metabox_posts_archive_selection_custom_link'];
if ( ! empty( $custom_archive_link ) ) {
$context['metabox_posts']['cta']['title'] = $custom_archive_link['title'] ?: _x( 'Bekijk alle berichten', 'Linktekst voor Hulpmiddel berichten', 'gctheme' );
$context['metabox_posts']['cta']['url'] = $custom_archive_link['url'];
}
}
}
foreach ( $metabox_item_ids as $post_id ) {
$item = prepare_card_content( get_post( $post_id ) );
$image = get_the_post_thumbnail_url( $post_id, IMAGESIZE_16x9 );
if ( $image ) {
// decorative image, no value for alt attr.
$item['img'] = '<img src="' . $image . '" alt="" />';
// Provide Image as URL instead of HTML?
// $item['img'] = $image;
// $item['img_alt'] = '';
}
$context['metabox_posts']['items'][] = $item;
}
$context['metabox_posts']['columncounter'] = count( $context['metabox_posts']['items'] );
}
}
/**
* (45) Related Richtlijnen
* ----------------------------- */
$metabox_richtlijnen = get_field( 'richtlijnen' );
if ( $metabox_richtlijnen && 'ja' === $metabox_richtlijnen['metabox_hulpmiddel_richtlijnen_show_or_not'] ) {
// Do we have a Hulpmiddel Term?
// Only continue if we do.
if ( $current_hulpmiddel_taxid && function_exists( 'prepare_richtlijn_card_content' ) ) {
$coupled_richtlijnen = $metabox_richtlijnen['metabox_hulpmiddel_richtlijnen_select'];
if ( $coupled_richtlijnen ) {
$metabox_items = array();
$default_title = _x( 'Hulp nodig?', 'default title for richtlijnen', 'gctheme' );
foreach ( $coupled_richtlijnen as $richtlijn ) {
$metabox_items[] = prepare_richtlijn_card_content( $richtlijn );
}
if ( ! empty( $metabox_items ) ) {
$context['metabox_hulpmiddel_richtlijnen'] = array();
$context['metabox_hulpmiddel_richtlijnen']['items'] = array();
$context['metabox_hulpmiddel_richtlijnen']['cta'] = $metabox_richtlijnen['metabox_hulpmiddel_richtlijnen_url_overview'];
$context['metabox_hulpmiddel_richtlijnen']['title'] = $metabox_richtlijnen['metabox_hulpmiddel_richtlijnen_titel'] ? $metabox_richtlijnen['metabox_hulpmiddel_richtlijnen_titel'] : $default_title;
$context['metabox_hulpmiddel_richtlijnen']['description'] = $metabox_richtlijnen['metabox_hulpmiddel_richtlijnen_omschrijving'] ?? '';
$richtlijnen_section_modifier = $metabox_richtlijnen['metabox_hulpmiddel_richtlijnen_section_style'];
if ( $richtlijnen_section_modifier !== 'default' ) {
$context['metabox_hulpmiddel_richtlijnen']['modifier'] = $richtlijnen_section_modifier;
}
$context['metabox_hulpmiddel_richtlijnen']['items'] = $metabox_items;
$context['metabox_hulpmiddel_richtlijnen']['columncounter'] = count( $context['metabox_hulpmiddel_richtlijnen']['items'] );
}
}
}
}
/**
* (50) profiles box
* ----------------------------- */
// name of field is 'group_profiles', not 'profiles', as to avoid possible conflicts with function 'gc_get_profiles'
// (located at [theme]]/includes/post_types/profile-post-type.php )
$metabox_profiles = get_field( 'group_profiles' );
if ( $metabox_profiles && 'ja' === $metabox_profiles['metabox_profiles_show_or_not'] ) {
$context['metabox_profiles'] = [];
$context['metabox_profiles']['title'] = $metabox_profiles['metabox_profiles_title'] ?: _x( 'Meer weten over dit hulpmiddel?', 'default title for profiles', 'gctheme' );
if ( function_exists( 'gc_get_profiles' ) ) {
$array_profiles = array();
foreach ( $metabox_profiles['metabox_profiles_linked_profiles'] as $profile ) {
// pass on the profile in rather specific date structure as required by gc_get_profiles
$item = array();
$item['profile'] = array();
$item['profile'][] = $profile;
$item['profile_label'] = '';
$array_profiles[] = $item;
}
$context['metabox_profiles']['profiles'] = gc_get_profiles( array( 'profiles' => $array_profiles ) );
}
}
/**
* (60) Contact form box
* (actually it's a Gravity Forms form)
* ----------------------------- */
$metabox_contactform_id = get_field( 'metabox_contactform_id' );
if ( $metabox_contactform_id ) {
$gravityforms_block = '<!-- wp:gravityforms/form {"formId":"' . $metabox_contactform_id . '"} /-->';
$parsed_blocks = do_blocks( $gravityforms_block );
if ( $parsed_blocks ) {
$context['metabox_contactform'] = $parsed_blocks;
}
}
/**
* (70) Partners / Logo's
* (we render the gc/logos Block in Theme's hulpmiddel-detail.twig)
* ----------------------------- */
// Require a filled in list for this section to show
$metabox_logos_list = get_field( 'logos_list' );
if ( $metabox_logos_list ) {
$context['metabox_logos'] = array(
'title' => get_field( 'logos_title' ),
'description' => get_field( 'logos_description' ),
'list' => $metabox_logos_list,
);
}
}
Timber::render( $templates, $context );