Same name and namespace in other branches
  1. 3.0.x src/Plugin/Field/FieldFormatter/ColorFieldFormatterSwatch.php \Drupal\color_field\Plugin\Field\FieldFormatter\ColorFieldFormatterSwatch::viewValue()
2 calls to ColorFieldFormatterSwatch::viewValue()
ColorFieldFormatterSwatch::viewElements dans src/Plugin/Field/FieldFormatter/ColorFieldFormatterSwatch.php
ColorFieldFormatterSwatchOptions::viewElements dans src/Plugin/Field/FieldFormatter/ColorFieldFormatterSwatchOptions.php

Fichier

src/Plugin/Field/FieldFormatter/ColorFieldFormatterSwatch.php, line 174

Classe

ColorFieldFormatterSwatch
Plugin implementation of the color_field swatch formatter.

Namespace

Drupal\color_field\Plugin\Field\FieldFormatter

Code

protected function viewValue(ColorFieldType $item) {
    $opacity = $this->getFieldSetting('opacity');
    $settings = $this->getSettings();
    $color_hex = new ColorHex($item->color, $item->opacity);
    if ($opacity && $settings['opacity']) {
        $rgbtext = $color_hex->toRgb()
            ->toString(TRUE);
    }
    else {
        $rgbtext = $color_hex->toRgb()
            ->toString(FALSE);
    }
    return $rgbtext;
}