From 0a8282411df95e3fb1a5371329c1e236403f12b3 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. * After discussing the needed feature among themselves, UX has decided that a separate field for homepage alerts was preferrable, because that space frequently needs a single line of text that does not replicate the uses of the existing title and body fields for the current alert information. ** Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/pw-93 ** How does this address that need: * First, we add a new field to the Location Attributes fieldset, named alert_frontpage. This field appears next to the other location alert fields (alert_title and alert_content), with help text advising that this new field should only have links added to it. * Second, we add a method to the widget class (which is provided by the hours plugin) to check for content in this new field. If content is found, it is included in the widget output below that location's entry. * The styling for this display is taken from the former styles for the Hayden renovation alert, which was statically added to this partial. * Because the parent theme's styles are changing, we bump the theme version. ** Document any side effects to this change: * This ticket is validating our choice to go with a monorepo for our WordPress application - as the changes being made might have spanned across several repositories in our previous infrastructure (one for the hours widget, one for the parent theme to change the styling, and potentially a third for the data model change - although that may have just been a configuration and not a code change before). * While the use of a class method and not a function in a tempalte is good, we are still mixing content and code because we have hard- coded location names, phone numbers, etc - as well as the post IDs for our actual locations. I'm choosing not to continue pulling on this thread, however. --- .../data/location/group_58e22931ab9f5.json | 21 +++++++++- .../src/class-display-widget-frontpage.php | 38 +++++++++++++++++++ .../templates/display-widget-frontpage.php | 24 ++++++++++++ .../css/scss/partials/_home.scss | 6 ++- web/app/themes/mitlib-parent/style.css | 2 +- 5 files changed, 88 insertions(+), 3 deletions(-) diff --git a/web/app/mu-plugins/mitlib-post/data/location/group_58e22931ab9f5.json b/web/app/mu-plugins/mitlib-post/data/location/group_58e22931ab9f5.json index 6f2163e8..1d5e720e 100644 --- a/web/app/mu-plugins/mitlib-post/data/location/group_58e22931ab9f5.json +++ b/web/app/mu-plugins/mitlib-post/data/location/group_58e22931ab9f5.json @@ -40,6 +40,25 @@ "tabs": "all", "delay": 0 }, + { + "key": "field_6643c15f0075d", + "label": "Alert Frontpage", + "name": "alert_frontpage", + "type": "wysiwyg", + "instructions": "This field is shown only on the front page hours widget. The content is automatically wrapped in a paragraph tag. The only allowed HTML tag is for links (a tags).", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "default_value": "", + "tabs": "all", + "toolbar": "full", + "media_upload": 0, + "delay": 0 + }, { "key": "field_24", "label": "Display Page", @@ -990,5 +1009,5 @@ "active": true, "description": "", "show_in_rest": 0, - "modified": 1671581913 + "modified": 1715716606 } \ No newline at end of file diff --git a/web/app/plugins/mitlib-pull-hours/src/class-display-widget-frontpage.php b/web/app/plugins/mitlib-pull-hours/src/class-display-widget-frontpage.php index 0500b6ba..0cf1ffce 100644 --- a/web/app/plugins/mitlib-pull-hours/src/class-display-widget-frontpage.php +++ b/web/app/plugins/mitlib-pull-hours/src/class-display-widget-frontpage.php @@ -83,6 +83,44 @@ public static function init() { register_widget( 'Mitlib\PullHours\Display_Widget_Frontpage' ); } + /** + * 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 void + */ + public function location_alert( $location_id ) { + $allowed_html = array( + 'a' => array( + 'href' => array(), + ), + 'p' => array(), + ); + + $query_args = array( + 'post_type' => 'location', + 'p' => $location_id, + 'post_status' => 'publish', + ); + $locations = new \WP_Query( $query_args ); + + while ( $locations->have_posts() ) { + $locations->the_post(); + $alert_frontpage = get_field( 'alert_frontpage' ); + if ( $alert_frontpage ) { + echo '
'; + echo wp_kses( $alert_frontpage, $allowed_html ); + echo '
'; + } + } + } + /** * Sanitize widget form values as they are saved. * 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..fc01f848 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 @@ -14,18 +14,30 @@

Barker Library

today
10-500617-253-0968
+location_alert( 322 ); +?>
Dewey Library
+location_alert( 313 ); +?>
Hayden Library
+location_alert( 452 ); +?> Show 3 More @@ -35,16 +47,28 @@

Rotch Library

today
7-238617-258-5592
+location_alert( 359 ); +?>
Distinctive Collections Reading Room
+location_alert( 504 ); +?>
Lewis Music Library
+location_alert( 473 ); +?> 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..49d9c442 100644 --- a/web/app/themes/mitlib-parent/css/scss/partials/_home.scss +++ b/web/app/themes/mitlib-parent/css/scss/partials/_home.scss @@ -199,11 +199,15 @@ body.page-home { } } - .location-hayden-reno { + .location-alert { padding: .5rem 1em; color: #008700; margin: 0; + @include bp-tablet--portrait { + padding: 0 1rem 1rem + } + p { margin-bottom: 0 !important; font-weight: 600; diff --git a/web/app/themes/mitlib-parent/style.css b/web/app/themes/mitlib-parent/style.css index 12c45a82..d14a6559 100644 --- a/web/app/themes/mitlib-parent/style.css +++ b/web/app/themes/mitlib-parent/style.css @@ -1,7 +1,7 @@ /* Theme Name: MITlib Parent Author: MIT Libraries -Version: 0.4 +Version: 0.5 Description: The parent theme for the MIT Libraries' Pentagram-designed identity. */