You are here

public static function Color::normalizeHexLength in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Component/Utility/Color.php \Drupal\Component\Utility\Color::normalizeHexLength()
  2. 10 core/lib/Drupal/Component/Utility/Color.php \Drupal\Component\Utility\Color::normalizeHexLength()

Normalize the hex color length to 6 characters for comparison.

Parameters

string $hex: The hex color to normalize.

Return value

string The 6 character hex color.

2 calls to Color::normalizeHexLength()
ColorTest::testNormalizeHexLength in core/tests/Drupal/Tests/Component/Utility/ColorTest.php
Tests Color::normalizeHexLength().
_color_rewrite_stylesheet in core/modules/color/color.module
Rewrites the stylesheet to match the colors in the palette.

File

core/lib/Drupal/Component/Utility/Color.php, line 100

Class

Color
Performs color conversions.

Namespace

Drupal\Component\Utility

Code

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;
}