From 8aa714a3809426b1424d3587b2a976e5a2de6e69 Mon Sep 17 00:00:00 2001 From: Bradley Date: Thu, 8 Aug 2024 15:52:45 +0100 Subject: [PATCH] Maybe have colour override working --- src/Twig/Component/Badge.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Twig/Component/Badge.php b/src/Twig/Component/Badge.php index 6fa0ea5..4610535 100644 --- a/src/Twig/Component/Badge.php +++ b/src/Twig/Component/Badge.php @@ -28,12 +28,16 @@ final class Badge { if (null !== $colour) { - $cases = array_map(fn(EnumBadge $b) => $b->name, EnumBadge::cases()); + $cases = array_map(fn(EnumBadge $b) => strtolower($b->name), EnumBadge::cases()); if (!in_array($colour, $cases)) { - throw new \RuntimeException(sprintf('"%s" is not a valid Badge colour. Available options are: %s', $colour, implode(", ", $cases))); + $formattedCases = implode(", ", array_map(fn(string $s) => '"'.$s.'"', $cases)); + throw new \RuntimeException(sprintf('"%s" is not a valid Badge colour. Available options are: %s', $colour, $formattedCases)); } + $colour = strtoupper($colour); + $palette = Badge::{$colour}->getPalette(); + } else { $palette = $object->getBadgeColour()->getPalette(); }