You are here

public function JQueryColorpickerService::formatColor in Jquery Colorpicker 8

Formats colors into a consistent format for database storage.

Turns non-scalar values into an empty string. Removes the leading # (hash) from the given value if one exists at the start of the string.

Parameters

mixed $color: The value to be formatted.

Return value

string The formatted string.

Overrides JQueryColorpickerServiceInterface::formatColor

File

src/Service/JQueryColorpickerService.php, line 17

Class

JQueryColorpickerService
The jQuery Colorpicker service.

Namespace

Drupal\jquery_colorpicker\Service

Code

public function formatColor($color) {
  if (is_scalar($color)) {
    $color = (string) $color;
    if (strlen($color)) {
      if (preg_match('/^#/', $color)) {
        $color = substr($color, 1);
      }
    }
  }
  else {
    $color = '';
  }
  return $color;
}