class ColorapiService in Color API 8
Service class for the Color API module.
Hierarchy
- class \Drupal\colorapi\Service\ColorapiService implements ColorapiServiceInterface
Expanded class hierarchy of ColorapiService
1 string reference to 'ColorapiService'
File
- src/
Service/ ColorapiService.php, line 10
Namespace
Drupal\colorapi\ServiceView source
class ColorapiService implements ColorapiServiceInterface {
/**
* {@inheritdoc}
*/
public function isValidHexadecimalColorString($string) {
return preg_match(HexColorInterface::HEXADECIMAL_COLOR_REGEX, $string);
}
/**
* {@inheritdoc}
*/
public function hexToRgb($hex, $colorIndex) {
$hex = str_replace("#", "", $hex);
if ($colorIndex == 'red') {
if (strlen($hex) == 3) {
$rgb_value = hexdec(substr($hex, 0, 1) . substr($hex, 0, 1));
}
else {
$rgb_value = hexdec(substr($hex, 0, 2));
}
}
elseif ($colorIndex == 'green') {
if (strlen($hex) == 3) {
$rgb_value = hexdec(substr($hex, 1, 1) . substr($hex, 1, 1));
}
else {
$rgb_value = hexdec(substr($hex, 2, 2));
}
}
if ($colorIndex == 'blue') {
if (strlen($hex) == 3) {
$rgb_value = hexdec(substr($hex, 2, 1) . substr($hex, 2, 1));
}
else {
$rgb_value = hexdec(substr($hex, 4, 2));
}
}
return $rgb_value;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ColorapiService:: |
public | function |
Helper function to convert hex to rgb. Overrides ColorapiServiceInterface:: |
|
ColorapiService:: |
public | function |