public function SignatureFormatter::viewElements in Signature Field 8
Builds a renderable array for a field value.
Parameters
\Drupal\Core\Field\FieldItemListInterface $items: The field values to be rendered.
string $langcode: The language that should be used to render the field.
Return value
array A renderable array for $items, as an array of child elements keyed by consecutive numeric indexes starting from 0.
Overrides FormatterInterface::viewElements
File
- src/
Plugin/ Field/ FieldFormatter/ SignatureFormatter.php, line 25
Class
- SignatureFormatter
- Plugin implementation of the 'field_signature_field_formatter' formatter.
Namespace
Drupal\signature_field\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = array();
foreach ($items as $delta => $item) {
$elements[$delta] = array(
// We create a render array to produce the desired markup,
// "<p style="color: #hexcolor">The color code ... #hexcolor</p>".
// See theme_html_tag().
'#type' => 'html_tag',
'#tag' => 'img',
'#attributes' => array(
'src' => $item->value,
),
);
}
return $elements;
}