X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Flib%2FDrupal%2FComponent%2FUtility%2FColor.php;fp=web%2Fcore%2Flib%2FDrupal%2FComponent%2FUtility%2FColor.php;h=e3cb56bc92691be5ab6d7426bd439c52e265ceb9;hp=aa296e94bece57f60a8366f42577822f7b5b0b0d;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/web/core/lib/Drupal/Component/Utility/Color.php b/web/core/lib/Drupal/Component/Utility/Color.php index aa296e94b..e3cb56bc9 100644 --- a/web/core/lib/Drupal/Component/Utility/Color.php +++ b/web/core/lib/Drupal/Component/Utility/Color.php @@ -94,4 +94,28 @@ class Color { return '#' . str_pad(dechex($out), 6, 0, STR_PAD_LEFT); } + /** + * Normalize the hex color length to 6 characters for comparison. + * + * @param string $hex + * The hex color to normalize. + * + * @return string + * The 6 character hex color. + */ + public static function normalizeHexLength($hex) { + // Ignore '#' prefixes. + $hex = ltrim($hex, '#'); + + if (strlen($hex) === 3) { + $hex[5] = $hex[2]; + $hex[4] = $hex[2]; + $hex[3] = $hex[1]; + $hex[2] = $hex[1]; + $hex[1] = $hex[0]; + } + + return '#' . $hex; + } + }