Skip to content

Commit dec3161

Browse files
Merge pull request #150 from MITLibraries/pw-93
Add location alert fields to homepage widget
2 parents 79a4a15 + 0a82824 commit dec3161

5 files changed

Lines changed: 88 additions & 3 deletions

File tree

web/app/mu-plugins/mitlib-post/data/location/group_58e22931ab9f5.json

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,25 @@
4040
"tabs": "all",
4141
"delay": 0
4242
},
43+
{
44+
"key": "field_6643c15f0075d",
45+
"label": "Alert Frontpage",
46+
"name": "alert_frontpage",
47+
"type": "wysiwyg",
48+
"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).",
49+
"required": 0,
50+
"conditional_logic": 0,
51+
"wrapper": {
52+
"width": "",
53+
"class": "",
54+
"id": ""
55+
},
56+
"default_value": "",
57+
"tabs": "all",
58+
"toolbar": "full",
59+
"media_upload": 0,
60+
"delay": 0
61+
},
4362
{
4463
"key": "field_24",
4564
"label": "Display Page",
@@ -990,5 +1009,5 @@
9901009
"active": true,
9911010
"description": "",
9921011
"show_in_rest": 0,
993-
"modified": 1671581913
1012+
"modified": 1715716606
9941013
}

web/app/plugins/mitlib-pull-hours/src/class-display-widget-frontpage.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,44 @@ public static function init() {
8383
register_widget( 'Mitlib\PullHours\Display_Widget_Frontpage' );
8484
}
8585

86+
/**
87+
* This function accepts the post ID of a location record, which will be used
88+
* to check if that location has its alert populated. If either of the two
89+
* fields for the location alert (alert_title or alert_content) are populated,
90+
* that content will be shown in a div.
91+
*
92+
* The function does not return anything.
93+
*
94+
* @param string $location_id The ID of a location record to look up.
95+
*
96+
* @return void
97+
*/
98+
public function location_alert( $location_id ) {
99+
$allowed_html = array(
100+
'a' => array(
101+
'href' => array(),
102+
),
103+
'p' => array(),
104+
);
105+
106+
$query_args = array(
107+
'post_type' => 'location',
108+
'p' => $location_id,
109+
'post_status' => 'publish',
110+
);
111+
$locations = new \WP_Query( $query_args );
112+
113+
while ( $locations->have_posts() ) {
114+
$locations->the_post();
115+
$alert_frontpage = get_field( 'alert_frontpage' );
116+
if ( $alert_frontpage ) {
117+
echo '<div class="location-alert">';
118+
echo wp_kses( $alert_frontpage, $allowed_html );
119+
echo '</div>';
120+
}
121+
}
122+
}
123+
86124
/**
87125
* Sanitize widget form values as they are saved.
88126
*

web/app/plugins/mitlib-pull-hours/templates/display-widget-frontpage.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,30 @@
1414
<h3><a class="name-location" href="/barker">Barker Library</a></h3><div class="hours"><span data-location-hours="Barker Library"></span> today</div><div class="location-info"><a href="/locations/#!barker-library" class="map-location">10-500</a><a href="tel:617-253-0968" class="phone"><span class="number">617-253-0968</span></a></div>
1515
</div>
1616
</div>
17+
<?php
18+
// Load location alerts for Barker (post 322).
19+
$this->location_alert( 322 );
20+
?>
1721
<div class="location">
1822
<a href="/dewey" aria-labelledby="dewey" class="img-loc dewey"><span class="sr" id="dewey">Dewey Library</span></a>
1923
<div class="wrap-loc-info">
2024
<h3><a class="name-location" href="/dewey">Dewey Library</a></h3><div class="hours"><span data-location-hours="Dewey Library"></span> today</div><div class="location-info"><a href="/locations/#!dewey-library" class="map-location">E53-100</a><a href="tel:617-253-5676" class="phone"><span class="number">617-253-5676</span></a></div>
2125
</div>
2226
</div>
27+
<?php
28+
// Load location alerts for Dewey (post 313).
29+
$this->location_alert( 313 );
30+
?>
2331
<div class="location">
2432
<a href="/hayden" aria-labelledby="hayden" class="img-loc hayden"><span class="sr" id="hayden">Hayden Library</span></a>
2533
<div class="wrap-loc-info">
2634
<h3><a class="name-location" href="/hayden">Hayden Library</a></h3><div class="hours"><span data-location-hours="Hayden Library"></span> today</div> <div class="location-info"><a href="/locations/#!hayden-library" class="map-location">14S-100</a><a href="tel:617-253-5671" class="phone"><span class="number">617-253-5671</span></a></div>
2735
</div>
2836
</div>
37+
<?php
38+
// Load location alerts for Hayden (post 452).
39+
$this->location_alert( 452 );
40+
?>
2941
<a href="#0" class="show-more hidden-non-mobile">
3042
<svg class="icon-arrow-down" version="1.1" xmlns="http://www.w3.org/2000/svg" x="0" y="0" width="16.3" height="9.4" viewBox="2.7 8.3 16.3 9.4" enable-background="new 2.7 8.3 16.3 9.4" xml:space="preserve"><path d="M18.982 9.538l-8.159 8.159L2.665 9.538l1.284-1.283 6.875 6.875 6.875-6.875L18.982 9.538z"/></svg>Show 3 More
3143
</a>
@@ -35,16 +47,28 @@
3547
<h3><a class="name-location" href="/rotch">Rotch Library</a></h3><div class="hours"><span data-location-hours="Rotch Library"></span> today</div><div class="location-info"><a href="/locations/#!rotch-library" class="map-location">7-238</a><a href="tel:617-258-5592" class="phone"><span class="number">617-258-5592</span></a></div>
3648
</div>
3749
</div>
50+
<?php
51+
// Load location alerts for Rotch (post 359).
52+
$this->location_alert( 359 );
53+
?>
3854
<div class="location hidden-mobile inactive-mobile">
3955
<a href="/distinctive-collections" aria-labelledby="dc" class="img-loc archives"><span class="sr" id="dc">Distinctive Collections Reading Room</span></a>
4056
<div class="wrap-loc-info">
4157
<h3><a class="name-location" href="/distinctive-collections">Distinctive Collections Reading Room</a></h3><div class="hours"><span data-location-hours="Distinctive Collections"></span> today</div><div class="location-info"><a href="/locations/#!distinctive-collections" class="map-location">14N-118</a><a href="tel:617-253-5690" class="phone"><span class="number">617-253-5690</span></a></div>
4258
</div>
4359
</div>
60+
<?php
61+
// Load location alerts for Distinctive Collections (post 504).
62+
$this->location_alert( 504 );
63+
?>
4464
<div class="location hidden-mobile inactive-mobile">
4565
<a href="/music" aria-labelledby="lewis" class="img-loc lewis"><span class="sr" id="lewis">Lewis Music Library</span></a>
4666
<div class="wrap-loc-info">
4767
<h3><a class="name-location" href="/music">Lewis Music Library</a></h3><div class="hours"><span data-location-hours="Lewis Music Library"></span> today</div><div class="location-info"><a href="/locations/#!lewis-music-library" class="map-location">14E-109</a><a href="tel:617-253-5689" class="phone"><span class="number">617-253-5689</span></a></div>
4868
</div>
4969
</div>
70+
<?php
71+
// Load location alerts for Lewis (post 473).
72+
$this->location_alert( 473 );
73+
?>
5074
<a href="/hours" class="button-primary--green full add-margin link-hours">All hours &amp; locations</a>

web/app/themes/mitlib-parent/css/scss/partials/_home.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,15 @@ body.page-home {
199199
}
200200
}
201201

202-
.location-hayden-reno {
202+
.location-alert {
203203
padding: .5rem 1em;
204204
color: #008700;
205205
margin: 0;
206206

207+
@include bp-tablet--portrait {
208+
padding: 0 1rem 1rem
209+
}
210+
207211
p {
208212
margin-bottom: 0 !important;
209213
font-weight: 600;

web/app/themes/mitlib-parent/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
Theme Name: MITlib Parent
33
Author: MIT Libraries
4-
Version: 0.4
4+
Version: 0.5
55
Description: The parent theme for the MIT Libraries' Pentagram-designed identity.
66
77
*/

0 commit comments

Comments
 (0)