protected function ColorapiDisplayFormatterBase::addHumanReadableNameToElement in Color API 8
Adds the human-readable color name to the output.
Note: Only added if the formatter settings are set to display the human-readable name, and a value exists for the name.
Parameters
array $element: The field formatter render array element the name is to be added to.
int $delta: The index of the element within a multivalue field.
\Drupal\colorapi\Plugin\Field\FieldType\ColorItem $item: The item being viewed.
4 calls to ColorapiDisplayFormatterBase::addHumanReadableNameToElement()
- ColorapiColorDisplayFormatter::viewElements in src/
Plugin/ Field/ FieldFormatter/ ColorapiColorDisplayFormatter.php - Builds a renderable array for a field value.
- ColorapiRawHexDisplayFormatter::viewElements in src/
Plugin/ Field/ FieldFormatter/ ColorapiRawHexDisplayFormatter.php - Builds a renderable array for a field value.
- ColorapiRawRgbDisplayFormatter::viewElements in src/
Plugin/ Field/ FieldFormatter/ ColorapiRawRgbDisplayFormatter.php - Builds a renderable array for a field value.
- ColorapiTextDisplayFormatter::viewElements in src/
Plugin/ Field/ FieldFormatter/ ColorapiTextDisplayFormatter.php - Builds a renderable array for a field value.
File
- src/
Plugin/ Field/ FieldFormatter/ ColorapiDisplayFormatterBase.php, line 64
Class
- ColorapiDisplayFormatterBase
- Base class for Color API Color Field Formatters.
Namespace
Drupal\colorapi\Plugin\Field\FieldFormatterCode
protected function addHumanReadableNameToElement(array &$element, $delta, ColorItem $item) {
if ($this
->getSetting('display_name') && ($color_name = $item
->getColorName())) {
if (strlen($color_name)) {
$element[$delta]['name'] = [
'#prefix' => '<p class="color_name">',
'#suffix' => '</p>',
'#markup' => $this
->t('Color: @color', [
'@color' => $item
->getColorName(),
]),
];
}
}
}