function Color::normalizeHexLength

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Component/Utility/Color.php \Drupal\Component\Utility\Color::normalizeHexLength()
  2. 8.9.x core/lib/Drupal/Component/Utility/Color.php \Drupal\Component\Utility\Color::normalizeHexLength()
  3. 11.x 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.

1 call to Color::normalizeHexLength()
ColorTest::testNormalizeHexLength in core/tests/Drupal/Tests/Component/Utility/ColorTest.php
Tests Color::normalizeHexLength().

File

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

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.