ColorapiRawRgbDisplayFormatter.php in Color API 8
File
src/Plugin/Field/FieldFormatter/ColorapiRawRgbDisplayFormatter.php
View source
<?php
namespace Drupal\colorapi\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
class ColorapiRawRgbDisplayFormatter extends ColorapiDisplayFormatterBase {
public function settingsSummary() {
$summary = [];
$summary['overview'] = $this
->t('Displays a RGB representation of the color, with no HTML wrappers.');
return $summary + parent::settingsSummary();
}
public function viewElements(FieldItemListInterface $items, $langcode) {
$element = [];
foreach ($items as $delta => $item) {
$this
->addHumanReadableNameToElement($element, $delta, $item);
$element[$delta]['color'] = [
'#markup' => 'RGB(' . $item
->getRed() . ', ' . $item
->getGreen() . ', ' . $item
->getBlue() . ')',
];
}
return $element;
}
}