ShipmentItemTable.php in Commerce Shipping 8.2
File
src/Plugin/Field/FieldFormatter/ShipmentItemTable.php
View source
<?php
namespace Drupal\commerce_shipping\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
class ShipmentItemTable extends FormatterBase {
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) {
$table[$delta] = [
'label' => [
'#markup' => $item
->getTitle(),
],
'quantity' => [
'#markup' => $item
->getQuantity(),
],
'amount' => [
'#markup' => $item
->getDeclaredValue(),
],
];
}
return [
0 => $table,
];
}
}
Classes
Name |
Description |
ShipmentItemTable |
Plugin implementation of the 'commerce_shipment_item_table' formatter. |