Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add location alert fields to homepage widget #150

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -990,5 +1009,5 @@
"active": true,
"description": "",
"show_in_rest": 0,
"modified": 1671581913
"modified": 1715716606
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<div class="location-alert">';
echo wp_kses( $alert_frontpage, $allowed_html );
echo '</div>';
}
}
}

/**
* Sanitize widget form values as they are saved.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,30 @@
<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>
</div>
</div>
<?php
// Load location alerts for Barker (post 322).
$this->location_alert( 322 );
?>
<div class="location">
<a href="/dewey" aria-labelledby="dewey" class="img-loc dewey"><span class="sr" id="dewey">Dewey Library</span></a>
<div class="wrap-loc-info">
<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>
</div>
</div>
<?php
// Load location alerts for Dewey (post 313).
$this->location_alert( 313 );
?>
<div class="location">
<a href="/hayden" aria-labelledby="hayden" class="img-loc hayden"><span class="sr" id="hayden">Hayden Library</span></a>
<div class="wrap-loc-info">
<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>
</div>
</div>
<?php
// Load location alerts for Hayden (post 452).
$this->location_alert( 452 );
?>
<a href="#0" class="show-more hidden-non-mobile">
<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
</a>
Expand All @@ -35,16 +47,28 @@
<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>
</div>
</div>
<?php
// Load location alerts for Rotch (post 359).
$this->location_alert( 359 );
?>
<div class="location hidden-mobile inactive-mobile">
<a href="/distinctive-collections" aria-labelledby="dc" class="img-loc archives"><span class="sr" id="dc">Distinctive Collections Reading Room</span></a>
<div class="wrap-loc-info">
<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>
</div>
</div>
<?php
// Load location alerts for Distinctive Collections (post 504).
$this->location_alert( 504 );
?>
<div class="location hidden-mobile inactive-mobile">
<a href="/music" aria-labelledby="lewis" class="img-loc lewis"><span class="sr" id="lewis">Lewis Music Library</span></a>
<div class="wrap-loc-info">
<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>
</div>
</div>
<?php
// Load location alerts for Lewis (post 473).
$this->location_alert( 473 );
?>
<a href="/hours" class="button-primary--green full add-margin link-hours">All hours &amp; locations</a>
6 changes: 5 additions & 1 deletion web/app/themes/mitlib-parent/css/scss/partials/_home.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion web/app/themes/mitlib-parent/style.css
Original file line number Diff line number Diff line change
@@ -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.

*/
Expand Down
Loading