Skip to content

Commit 8525c91

Browse files
authored
Merge pull request #530 from devgeniem/TMS-1093
TMS-1093: Add graphics for dynamic event main images
2 parents b0a3ad4 + 631c5aa commit 8525c91

File tree

5 files changed

+107
-24
lines changed

5 files changed

+107
-24
lines changed

CHANGELOG.MD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
- TMS-1093: Add graphics for dynamic event main images
11+
1012
## [1.59.9] - 2025-04-02
1113

1214
- TMS-1108: Add new Häive color-theme

lib/Eventz.php

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Eventz implements Controller {
2121
/**
2222
* Hooks
2323
*/
24-
public function hooks() : void {
24+
public function hooks(): void {
2525
add_action(
2626
'wp_ajax_event_search',
2727
Closure::fromCallable( [ $this, 'admin_event_search_callback' ] )
@@ -31,7 +31,7 @@ public function hooks() : void {
3131
/**
3232
* Admin event search callback
3333
*/
34-
protected function admin_event_search_callback() : void {
34+
protected function admin_event_search_callback(): void {
3535
$params = $_GET['params'] ?? []; // phpcs:ignore
3636
$post_id = $_GET['post_id'] ?? 0; // phpcs:ignore
3737
$event = get_field( 'event', $post_id );
@@ -79,7 +79,7 @@ protected function admin_event_search_callback() : void {
7979
*
8080
* @return array
8181
*/
82-
public static function normalize_event( $event ) : array {
82+
public static function normalize_event( $event ): array {
8383
$lang_key = Localization::get_current_language();
8484

8585
if ( ! empty( $event->topics ) ) {
@@ -176,6 +176,7 @@ public static function normalize_event( $event ) : array {
176176
'image' => $image ?? null,
177177
'url' => static::get_event_url( $event->_id ),
178178
'is_dynamic' => static::get_dynamic_event( $event->_id ),
179+
'graphic_field' => static::get_dynamic_event_fields( $event->_id ),
179180
];
180181
}
181182

@@ -186,7 +187,7 @@ public static function normalize_event( $event ) : array {
186187
*
187188
* @return array
188189
*/
189-
public static function normalize_event_title( $event ) : array {
190+
public static function normalize_event_title( $event ): array {
190191
return [
191192
'name' => $event->name ?? null,
192193
];
@@ -199,7 +200,7 @@ public static function normalize_event_title( $event ) : array {
199200
*
200201
* @return array
201202
*/
202-
public static function normalize_event_description( $event ) : array {
203+
public static function normalize_event_description( $event ): array {
203204
return [
204205
'short_description' => nl2br( $event->descriptionShort ) ?? null,
205206
];
@@ -212,7 +213,7 @@ public static function normalize_event_description( $event ) : array {
212213
*
213214
* @return array
214215
*/
215-
public static function normalize_event_url( $event ) : array {
216+
public static function normalize_event_url( $event ): array {
216217
return [
217218
'url' => static::get_event_url( $event->_id ),
218219
];
@@ -410,7 +411,7 @@ public static function get_as_datetime( $value ) {
410411
*
411412
* @return array|null
412413
*/
413-
public static function get_event_price_info( $event ) : ?array {
414+
public static function get_event_price_info( $event ): ?array {
414415
if ( empty( $event ) || empty( $event->price ) ) {
415416
return null;
416417
}
@@ -437,7 +438,7 @@ public static function get_event_price_info( $event ) : ?array {
437438
*
438439
* @return string|null
439440
*/
440-
public static function format_price( $price ) : ?string {
441+
public static function format_price( $price ): ?string {
441442
if ( property_exists( $price, 'isFree' ) ) {
442443
return __( 'Free', 'tms-theme-base' );
443444
}
@@ -467,7 +468,7 @@ public static function format_price( $price ) : ?string {
467468
*
468469
* @return array
469470
*/
470-
public static function get_area_info( object $event ) : string {
471+
public static function get_area_info( object $event ): string {
471472
return implode( ',', $event->targets );
472473
}
473474

@@ -478,7 +479,7 @@ public static function get_area_info( object $event ) : string {
478479
*
479480
* @return array
480481
*/
481-
public static function get_target_info( object $event ) : string {
482+
public static function get_target_info( object $event ): string {
482483
return implode( ',', $event->targets );
483484
}
484485

@@ -489,7 +490,7 @@ public static function get_target_info( object $event ) : string {
489490
*
490491
* @return array
491492
*/
492-
public static function get_tag_info( object $event ) : string {
493+
public static function get_tag_info( object $event ): string {
493494
return implode( ',', $event->tags );
494495
}
495496

@@ -609,7 +610,7 @@ public static function get_event_entries( $event ) {
609610
*
610611
* @return string
611612
*/
612-
public static function get_event_url( string $event_id ) : string {
613+
public static function get_event_url( string $event_id ): string {
613614
$dynamic_events = DynamicEvent::get_link_list();
614615

615616
if ( isset( $dynamic_events[ $event_id ] ) ) {
@@ -630,14 +631,31 @@ public static function get_event_url( string $event_id ) : string {
630631
return '#';
631632
}
632633

634+
/**
635+
* Get dynamic events custom fields
636+
*
637+
* @param string $event_id Event's API ID.
638+
*
639+
* @return array
640+
*/
641+
public static function get_dynamic_event_fields( string $event_id ): array {
642+
$dynamic_events = DynamicEvent::get_event_graphic_field();
643+
644+
if ( isset( $dynamic_events[ $event_id . '_graphic' ] ) ) {
645+
return $dynamic_events[ $event_id . '_graphic' ];
646+
}
647+
648+
return [];
649+
}
650+
633651
/**
634652
* Get dynamic events
635653
*
636654
* @param string $event_id Event's API ID.
637655
*
638656
* @return string
639657
*/
640-
public static function get_dynamic_event( string $event_id ) : string {
658+
public static function get_dynamic_event( string $event_id ): string {
641659
$dynamic_events = DynamicEvent::get_link_list();
642660

643661
if ( isset( $dynamic_events[ $event_id ] ) ) {

lib/PostType/DynamicEvent.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,40 @@ public static function get_link_list() : array {
216216

217217
return $dynamic_events;
218218
}
219+
220+
/**
221+
* Get custom fields
222+
*
223+
* @return array
224+
*/
225+
public static function get_event_graphic_field() : array {
226+
$dynamic_events = [];
227+
228+
$the_query = new \WP_Query( [
229+
'post_type' => self::SLUG,
230+
'posts_per_page' => - 1,
231+
'fields' => 'ids',
232+
'no_found_rows' => true,
233+
'post_status' => 'publish',
234+
] );
235+
236+
if ( ! $the_query->have_posts() ) {
237+
return $dynamic_events;
238+
}
239+
240+
$theme_stylesheet_uri = \get_stylesheet_directory_uri();
241+
242+
foreach ( $the_query->posts as $dynamic_event_id ) {
243+
$api_id = \get_field( 'event', $dynamic_event_id );
244+
$graphic_field = \get_field( 'graphic', $dynamic_event_id );
245+
246+
if ( $api_id ) {
247+
if ( $graphic_field && $graphic_field !== 'none' ) {
248+
$dynamic_events[ $api_id . '_graphic' ][] = $theme_stylesheet_uri . '/assets/images/' . $graphic_field . '.svg';
249+
}
250+
}
251+
}
252+
253+
return $dynamic_events;
254+
}
219255
}

models/single-dynamic-event-cpt.php

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ class SingleDynamicEventCpt extends PageEvent {
2020
* Hooks
2121
*/
2222
public function hooks() : void {
23-
add_filter( 'tms/theme/breadcrumbs/show_breadcrumbs_in_header', fn() => false );
23+
\add_filter( 'tms/theme/breadcrumbs/show_breadcrumbs_in_header', fn() => false );
2424

25-
add_filter(
25+
\add_filter(
2626
'tms/base/breadcrumbs/after_prepare',
2727
Closure::fromCallable( [ $this, 'alter_breadcrumbs' ] )
2828
);
@@ -34,18 +34,45 @@ public function hooks() : void {
3434
* @return false|int
3535
*/
3636
public function hero_image() {
37-
return has_post_thumbnail()
38-
? get_post_thumbnail_id()
37+
return \has_post_thumbnail()
38+
? \get_post_thumbnail_id()
3939
: false;
4040
}
4141

42+
/**
43+
* Hero image URL
44+
*
45+
* @return false|string
46+
*/
47+
public function hero_image_url() {
48+
return \has_post_thumbnail()
49+
? \get_the_post_thumbnail_url()
50+
: false;
51+
}
52+
53+
/**
54+
* Hero image graphic field
55+
*
56+
* @return false|string
57+
*/
58+
public function hero_image_graphic() {
59+
$graphic_field = \get_field( 'graphic' );
60+
$hero_graphic = null;
61+
62+
if ( $graphic_field && $graphic_field !== 'none' ) {
63+
$hero_graphic = \get_stylesheet_directory_uri() . '/assets/images/' . $graphic_field . '.svg';
64+
}
65+
66+
return $hero_graphic;
67+
}
68+
4269
/**
4370
* Get event id
4471
*
4572
* @return string
4673
*/
4774
protected function get_event_id() : string {
48-
return get_field( 'event' ) ?? '';
75+
return \get_field( 'event' ) ?? '';
4976
}
5077

5178
/**
@@ -56,16 +83,16 @@ protected function get_event_id() : string {
5683
* @return array
5784
*/
5885
public function alter_breadcrumbs( array $breadcrumbs ) : array {
59-
$referer = wp_get_referer();
86+
$referer = \wp_get_referer();
6087
$home_url = DPT_PLL_ACTIVE && function_exists( 'pll_current_language' )
61-
? pll_home_url()
62-
: home_url();
88+
? \pll_home_url()
89+
: \home_url();
6390

6491
if ( false === strpos( $referer, $home_url ) ) {
6592
return $breadcrumbs;
6693
}
6794

68-
$parent = get_page_by_path(
95+
$parent = \get_page_by_path(
6996
str_replace( $home_url, '', $referer )
7097
);
7198

@@ -77,7 +104,7 @@ public function alter_breadcrumbs( array $breadcrumbs ) : array {
77104

78105
$breadcrumbs[] = [
79106
'title' => $parent->post_title,
80-
'permalink' => get_the_permalink( $parent->ID ),
107+
'permalink' => \get_the_permalink( $parent->ID ),
81108
];
82109

83110
$breadcrumbs[] = $last;

partials/views/single-dynamic-event/single-dynamic-event-hero-meta.dust

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
{/event.normalized.location}
3131

3232
{?event.normalized.link_purchase_ticket}
33-
<div class="has-width-100 mt-3">
33+
<div class="has-width-100 has-text-left mt-3">
3434
<a href="{event.normalized.link_purchase_ticket.url|url}" target="_blank" class="is-inline-block button is-small is-primary">
3535
{event.normalized.link_purchase_ticket.name|html}
3636
</a>

0 commit comments

Comments
 (0)