-
Notifications
You must be signed in to change notification settings - Fork 9
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
Modify WFO promo block to serve data from the WFO info content type #1555
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,17 +25,56 @@ public function build() | |
|
||
$promo = $this->entityTypeService->getLatestNodeFromWFO( | ||
$grid->wfo, | ||
"wfo_promo", | ||
"wfo_info", | ||
); | ||
|
||
// If we actually have a story, pass its ID on for the template | ||
// If there is WFO info, pull out the parts that should be rendered | ||
// in the WFO promo block on the forecast page. | ||
if ($promo) { | ||
$name = $promo->field_wfo->entity->name->value; | ||
$code = $promo->field_wfo->entity->field_wfo_code->value; | ||
|
||
$about = $promo->body; | ||
$phone = $promo->field_phone_number_opt ?? false; | ||
|
||
$facebook = $promo->field_facebook_url ?? false; | ||
$twitter = $promo->field_twitter_url ?? false; | ||
$youtube = $promo->field_youtube_url ?? false; | ||
|
||
$social = false; | ||
if ($facebook || $twitter || $youtube) { | ||
$social = [ | ||
"facebook" => $facebook, | ||
"twitter" => $twitter, | ||
"youtube" => $youtube, | ||
]; | ||
} | ||
Comment on lines
+44
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inspired by @eric-gade's comment in #1542 |
||
|
||
return [ | ||
"name" => $name, | ||
"code" => $code, | ||
"about" => $about, | ||
"phone" => $phone, | ||
"social" => $social, | ||
]; | ||
} | ||
|
||
// If there's not a WFO info, just return the name and code. | ||
$taxonomyTerm = $this->entityTypeService->getWFOEntity($grid->wfo); | ||
if ($taxonomyTerm) { | ||
$name = $taxonomyTerm->get("name")->getString(); | ||
|
||
return [ | ||
"node" => $promo->id(), | ||
"name" => $name, | ||
"code" => $grid->wfo, | ||
"phone" => false, | ||
"social" => false, | ||
]; | ||
} | ||
} | ||
|
||
// If we get here, it's because either the location doesn't have a grid | ||
// point and thus no WFO, or else because we don't know about the WFO. | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,4 +90,15 @@ public function getLatestNodeFromWFO($wfo, $nodeType) | |
|
||
return $this->getLatestNodeByTerm($termID, "field_wfo", $nodeType); | ||
} | ||
|
||
public function getWFOEntity($wfo) | ||
{ | ||
$term = $this->entityTypeManager | ||
->getStorage("taxonomy_term") | ||
->loadByProperties(["field_wfo_code" => $wfo]); | ||
if (count($term) > 0) { | ||
return array_pop($term); | ||
} | ||
return false; | ||
} | ||
Comment on lines
+94
to
+103
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice |
||
} |
29 changes: 28 additions & 1 deletion
29
web/themes/new_weather_theme/templates/block/block--weathergov-wfo-promo.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,28 @@ | ||
{{ drupal_entity("node", content.node) }} | ||
<div class="grid-container padding-x-2"> | ||
<div class="grid-row"> | ||
<div class="grid-col tablet-lg:grid-offset-2 tablet-lg:grid-col-8"> | ||
<h3 class="wx-visual-h2 text-normal text-primary-darker"> {{ "Your Local Forecast Office" | t }} </h3> | ||
<h4 class="wx-visual-h3 margin-bottom-1"><a href="/offices/{{ content.code }}">{{ content.name }}</a></h4> | ||
<p class="line-height-sans-4 margin-top-0"> | ||
{{ content.about | view }} | ||
</p> | ||
|
||
{% set hasPhone = content.phone | length %} | ||
{% if hasPhone > 0 %} | ||
{{ content.phone | view }} | ||
{% endif %} | ||
|
||
{% if content.social is not same as false %} | ||
<p class="font-family-mono font-mono-sm text-bold text-primary-darker text-uppercase margin-bottom-1"> | ||
{{ "Find us on" | t }} | ||
</p> | ||
<ul class="usa-list usa-list--unstyled"> | ||
{{ content.social.facebook| view }} | ||
{{ content.social.youtube | view }} | ||
{{ content.social.twitter | view }} | ||
</ul> | ||
{% endif %} | ||
|
||
</div> | ||
</div> | ||
</div> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another moment where I'm like "how did he figure this out?"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lord, I don't remember. I just copied it from elsewhere in the tests.