Same name and namespace in other branches
- 8.x-2.x src/Plugin/Field/FieldFormatter/ColorFieldFormatterSwatch.php \Drupal\color_field\Plugin\Field\FieldFormatter\ColorFieldFormatterSwatch::viewValue()
View an individual field value.
Paramètres
\Drupal\color_field\Plugin\Field\FieldType\ColorFieldType $item: The field.
Return value
string The field value as rgb/rgba string.
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 187
Classe
- ColorFieldFormatterSwatch
- Plugin implementation of the color_field swatch formatter.
Namespace
Drupal\color_field\Plugin\Field\FieldFormatterCode
protected function viewValue(ColorFieldType $item) : string {
$opacity = $this->getFieldSetting('opacity');
$settings = $this->getSettings();
$color_hex = new ColorHex($item->color, $item->opacity);
return $opacity && $settings['opacity'] ? $color_hex->toRgb()
->toString(TRUE) : $color_hex->toRgb()
->toString(FALSE);
}