From 2713639f8d3446b5254b96cf8d484a50d14cc132 Mon Sep 17 00:00:00 2001 From: Matthew Bernhardt Date: Mon, 13 May 2024 15:44:51 -0400 Subject: [PATCH] Add location alert fields to homepage widget ** Why are these changes being introduced: * There is an upcoming closure to the Hayden library, and we want to enable UXWS staff to be able to add alerts to the homepage for cases like this without asking for EngX to modify static templates. ** Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/pw-93 ** How does this address that need: * This adds a function to the homepage locations widget (part of the hours plugin), to check each location's record to see if there are any location alerts. If either the alert title or alert content field has been populated, they are shown to the user below that location's entry on the homepage. ** Document any side effects to this change: * The alert_title and alert_content fields already exist as part of the location record type. Those fields are currently shown on the location page and the hours page, but only if the title is populated (the content field alone being populated does not suffice). This change hooks into those fields and displays them in a new location, which may have an impact on how UXWS handles these fields. * This does not get us entirely away from mixing code and content, as the homepage hours widget still has hard-coded values for other location information (location names, which locations are shown, and in what order, etc). * The old CSS styles for the hayden renovation alert have been renamed to be just 'location-alert'. --- .../templates/display-widget-frontpage.php | 70 +++++++++++++++++++ .../css/scss/partials/_home.scss | 2 +- 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/web/app/plugins/mitlib-pull-hours/templates/display-widget-frontpage.php b/web/app/plugins/mitlib-pull-hours/templates/display-widget-frontpage.php index 3a977f9a..929bcf8e 100644 --- a/web/app/plugins/mitlib-pull-hours/templates/display-widget-frontpage.php +++ b/web/app/plugins/mitlib-pull-hours/templates/display-widget-frontpage.php @@ -6,6 +6,52 @@ * @since 0.6.0 */ +/** + * This function accepts the post ID of a location record, which will be used + * to check if that location has its alert populated. If either of the two + * fields for the location alert (alert_title or alert_content) are populated, + * that content will be shown in a div. + * + * The function does not return anything. + * + * @param string $location_id The ID of a location record to look up. + * + * @return none + */ +function location_alert( $location_id ) { + $allowed_html = array( + 'a' => array( + 'href' => array(), + ), + 'br' => array(), + 'em' => array(), + 'p' => array(), + 'strong' => array(), + ); + + $query_args = array( + 'post_type' => 'location', + 'p' => $location_id, + 'post_status' => 'publish', + 'meta_key' => 'primary_location', + 'meta_value' => 1, + 'orderby' => 'title', + 'order' => 'ASC', + 'ignore_sticky_posts' => 1, + ); + $locations = new \WP_Query($query_args); + while ( $locations->have_posts() ) { + $locations->the_post(); + $alert_title = get_field( 'alert_title' ); + $alert_content = get_field( 'alert_content' ); + if ( $alert_title || $alert_content ) { + echo '
'; + echo wp_kses( $alert_title, $allowed_html ); + echo wp_kses( $alert_content, $allowed_html ); + echo '
'; + } + } +} ?>
@@ -14,18 +60,30 @@

Barker Library

today
+
Dewey Library
+
Hayden Library
+ Show 3 More @@ -35,16 +93,28 @@

Rotch Library

today
7-238617-258-5592
+
Distinctive Collections Reading Room
+
Lewis Music Library
+ All hours & locations diff --git a/web/app/themes/mitlib-parent/css/scss/partials/_home.scss b/web/app/themes/mitlib-parent/css/scss/partials/_home.scss index 9941f938..b228c49c 100644 --- a/web/app/themes/mitlib-parent/css/scss/partials/_home.scss +++ b/web/app/themes/mitlib-parent/css/scss/partials/_home.scss @@ -199,7 +199,7 @@ body.page-home { } } - .location-hayden-reno { + .location-alert { padding: .5rem 1em; color: #008700; margin: 0;