Same name and namespace in other branches
- 3.0.x src/Plugin/Field/FieldType/ColorFieldType.php \Drupal\color_field\Plugin\Field\FieldType\ColorFieldType::preSave()
Fichier
-
src/
Plugin/ Field/ FieldType/ ColorFieldType.php, line 221
Classe
- ColorFieldType
- Plugin implementation of the 'color_type' field type.
Namespace
Drupal\color_field\Plugin\Field\FieldTypeCode
public function preSave() {
parent::preSave();
if ($format = $this->getSetting('format')) {
$color = $this->color;
// Clean up data and format it.
$color = trim($color);
if (substr($color, 0, 1) === '#') {
$color = substr($color, 1);
}
switch ($format) {
case '#HEXHEX':
$color = '#' . strtoupper($color);
break;
case 'HEXHEX':
$color = strtoupper($color);
break;
case '#hexhex':
$color = '#' . strtolower($color);
break;
case 'hexhex':
$color = strtolower($color);
break;
}
$this->color = $color;
}
if (!$this->getSetting('opacity')) {
unset($this->opacity);
}
}