-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1804 from weather-gov/eg-1681-alaska-afds
Fix Anchorage WFO Promo links
- Loading branch information
Showing
5 changed files
with
68 additions
and
4 deletions.
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
45 changes: 45 additions & 0 deletions
45
web/modules/weather_data/src/Service/WeatherTwigExtension.php
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Drupal\weather_data\Service; | ||
|
||
use Twig\Extension\AbstractExtension; | ||
use Twig\TwigFilter; | ||
use Twig\TwigFunction; | ||
use Twig\Extension\ExtensionInterface; | ||
|
||
class WeatherTwigExtension extends AbstractExtension | ||
{ | ||
public function getFunctions() | ||
{ | ||
return [ | ||
new TwigFunction( | ||
"normalize_wfo", | ||
[$this, "normalizeWFO"], | ||
["is_safe" => ["html"]], | ||
), | ||
]; | ||
} | ||
|
||
public function getFilters() | ||
{ | ||
return [new TwigFilter("normalize_wfo", [$this, "normalizeWFO"])]; | ||
} | ||
|
||
/** | ||
* Handle the edge cases of WFO codes | ||
* for Alaska/Anchorage | ||
*/ | ||
public function normalizeWFO($wfo) | ||
{ | ||
if (!$wfo) { | ||
return ""; | ||
} | ||
$anchorageAlternates = ["alu", "aer"]; | ||
$isAlternate = in_array(strtolower($wfo), $anchorageAlternates); | ||
if ($isAlternate) { | ||
return "AFC"; | ||
} | ||
|
||
return $wfo; | ||
} | ||
} |
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
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