public function ShipmentItemTable::viewElements in Commerce Shipping 8.2
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/ ShipmentItemTable.php, line 24
Class
- ShipmentItemTable
- Plugin implementation of the 'commerce_shipment_item_table' formatter.
Namespace
Drupal\commerce_shipping\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$table = [
'#type' => 'table',
'#header' => [
'label' => $this
->t('Title'),
'quantity' => $this
->t('Quantity'),
'amount' => $this
->t('Amount'),
],
];
foreach ($items
->getShipmentItems() as $delta => $item) {
/** @var \Drupal\commerce_shipping\ShipmentItem $item */
$table[$delta] = [
'label' => [
'#markup' => $item
->getTitle(),
],
'quantity' => [
'#markup' => $item
->getQuantity(),
],
'amount' => [
'#markup' => $item
->getDeclaredValue(),
],
];
}
return [
0 => $table,
];
}