You are here

protected function ColorFieldFormatterSwatch::viewValue in Color Field 8.2

2 calls to ColorFieldFormatterSwatch::viewValue()
ColorFieldFormatterSwatch::viewElements in src/Plugin/Field/FieldFormatter/ColorFieldFormatterSwatch.php
Builds a renderable array for a field value.
ColorFieldFormatterSwatchOptions::viewElements in src/Plugin/Field/FieldFormatter/ColorFieldFormatterSwatchOptions.php
Builds a renderable array for a field value.

File

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

Class

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;
}