Same name and namespace in other branches
  1. 8.x-2.x src/Feeds/Target/Color.php \Drupal\color_field\Feeds\Target\Color::prepareValue() 1 comment

File

src/Feeds/Target/Color.php, line 68

Class

Color
Defines a color field mapper.

Namespace

Drupal\color_field\Feeds\Target

Code

protected function prepareValue($delta, array &$values) {
    // Clean up data and format it.
    $color = trim($values['color']);
    if (str_starts_with($color, '#')) {
        $color = substr($color, 1);
    }
    switch ($this->configuration['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;
    }
    $values['color'] = $color;
    $values['opacity'] = $values['opacity'] ? (double) $values['opacity'] : 0.0;
}