class JQueryColorpickerService in Jquery Colorpicker 8
The jQuery Colorpicker service.
Hierarchy
- class \Drupal\jquery_colorpicker\Service\JQueryColorpickerService implements JQueryColorpickerServiceInterface uses StringTranslationTrait
Expanded class hierarchy of JQueryColorpickerService
1 file declares its use of JQueryColorpickerService
- jQueryColorpickerServiceTest.php in tests/
src/ Unit/ Service/ jQueryColorpickerServiceTest.php
1 string reference to 'JQueryColorpickerService'
File
- src/
Service/ JQueryColorpickerService.php, line 10
Namespace
Drupal\jquery_colorpicker\ServiceView source
class JQueryColorpickerService implements JQueryColorpickerServiceInterface {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
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;
}
/**
* {@inheritdoc}
*/
public function validateColor($color) {
$error = FALSE;
if (is_string($color) || is_int($color)) {
if (strlen($color) != 6) {
$error = $this
->t('Color values must be exactly six characters in length');
}
elseif (!preg_match('/^[0-9a-fA-F]{6}$/i', $color)) {
$error = $this
->t("You entered an invalid value for the color. Colors must be hexadecimal, and can only contain the characters '0-9', 'a-f' and/or 'A-F'.");
}
}
else {
$error = $this
->t('Color must be a string or an integer');
}
return $error;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
JQueryColorpickerService:: |
public | function |
Formats colors into a consistent format for database storage. Overrides JQueryColorpickerServiceInterface:: |
|
JQueryColorpickerService:: |
public | function |
Validates a hecidecimal color string. Overrides JQueryColorpickerServiceInterface:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |