Skip to content

Commit

Permalink
Merge pull request #2252 from weather-gov/lmm/opt-out-weather-story
Browse files Browse the repository at this point in the history
add opt out for weather stories
  • Loading branch information
loganmcdonald-noaa authored Feb 13, 2025
2 parents c03b277 + f38fee2 commit 1316e33
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ langcode: en
status: true
dependencies:
config:
- field.field.taxonomy_term.weather_forecast_offices.field_weather_story_opt_out
- field.field.taxonomy_term.weather_forecast_offices.field_wfo_code
- taxonomy.vocabulary.weather_forecast_offices
id: taxonomy_term.weather_forecast_offices.default
targetEntityType: taxonomy_term
bundle: weather_forecast_offices
mode: default
content:
field_weather_story_opt_out:
type: boolean_checkbox
weight: 26
region: content
settings:
display_label: true
third_party_settings: { }
field_wfo_code:
type: string_textfield
weight: 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ langcode: en
status: true
dependencies:
config:
- field.field.taxonomy_term.weather_forecast_offices.field_weather_story_opt_out
- field.field.taxonomy_term.weather_forecast_offices.field_wfo_code
- taxonomy.vocabulary.weather_forecast_offices
module:
Expand All @@ -19,6 +20,16 @@ content:
third_party_settings: { }
weight: 0
region: content
field_weather_story_opt_out:
type: boolean
label: above
settings:
format: default
format_custom_false: ''
format_custom_true: ''
third_party_settings: { }
weight: 2
region: content
field_wfo_code:
type: string
label: above
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
uuid: 7eeed965-8e2c-4195-8bbd-0d169018347e
langcode: en
status: true
dependencies:
config:
- field.storage.taxonomy_term.field_weather_story_opt_out
- taxonomy.vocabulary.weather_forecast_offices
id: taxonomy_term.weather_forecast_offices.field_weather_story_opt_out
field_name: field_weather_story_opt_out
entity_type: taxonomy_term
bundle: weather_forecast_offices
label: weather_story_opt_out
description: ''
required: false
translatable: false
default_value:
-
value: 0
default_value_callback: ''
settings:
on_label: 'Select to opt out of weather stories'
off_label: 'Opted into weather stories by default'
field_type: boolean
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
uuid: c84a451b-c210-4374-a479-4ba4866160e8
langcode: en
status: true
dependencies:
module:
- taxonomy
id: taxonomy_term.field_weather_story_opt_out
field_name: field_weather_story_opt_out
entity_type: taxonomy_term
type: boolean
settings: { }
module: core
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ final class WeatherStoryImageBlockTest extends Base
$this->entityService
->method("getLatestWeatherStoryImageFromWFO")
->willReturn([]);

$this->entityService
->method("getWFOTaxonomyOptOut")
->willReturn(0);

return;
}

Expand Down Expand Up @@ -82,6 +87,10 @@ final class WeatherStoryImageBlockTest extends Base
$this->entityService
->method("getLatestWeatherStoryImageFromWFO")
->willReturn($story);

$this->entityService
->method("getWFOTaxonomyOptOut")
->willReturn(0);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ public function build()
}

if ($wfo) {
$weatherStoryOptOut = $this->entityTypeService->getWFOTaxonomyOptOut($wfo);
$story = $this->entityTypeService->getLatestWeatherStoryImageFromWFO(
$wfo,
"wfo_weather_story_upload",
);

// If we actually have a story, now we can go about pulling data
// from it to pass along to the template.
if ($story) {
if ($story && $weatherStoryOptOut == 0) {
// because the weather story description is comes via a xml
// CDATA tag, we need to strip tags and surrounding whitespace.
$description = $story->get("field_description")->value;
Expand Down
15 changes: 15 additions & 0 deletions web/modules/weather_data/src/Service/WeatherEntityService.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ public function getLatestNodeFromWeatherEvent($eventType, $nodeType)
);
}

public function getWFOTaxonomyOptOut($wfoCode)
{
$wfo_results = \Drupal::entityTypeManager()
->getStorage("taxonomy_term")
->loadByProperties([
"vid" => "weather_forecast_offices",
"field_wfo_code" => strtoupper($wfoCode),
]);
$wfo_results = array_values($wfo_results); // Indices can be totally random numbers!
if (count($wfo_results) == 0) {
throw new NotFoundHttpException();
}
return $wfo_results[0]->get('field_weather_story_opt_out')->getValue()[0]['value'];
}

public function getLatestNodeFromWFO($wfo, $nodeType)
{
// Get the ID for the WFO taxonomy term that matches our grid WFO.
Expand Down

0 comments on commit 1316e33

Please sign in to comment.