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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.