OrderItemTable.php in Commerce Core 8.2
File
modules/order/src/Plugin/Field/FieldFormatter/OrderItemTable.php
View source
<?php
namespace Drupal\commerce_order\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
class OrderItemTable extends FormatterBase {
public function viewElements(FieldItemListInterface $items, $langcode) {
$order = $items
->getEntity();
$elements = [];
$order_item_ids = array_column($order
->get('order_items')
->getValue(), 'target_id');
$elements[0] = [
'#type' => 'view',
'#name' => 'commerce_order_item_table',
'#arguments' => $order_item_ids ? [
implode('+', $order_item_ids),
] : NULL,
'#embed' => TRUE,
];
return $elements;
}
public static function isApplicable(FieldDefinitionInterface $field_definition) {
$entity_type = $field_definition
->getTargetEntityTypeId();
$field_name = $field_definition
->getName();
return $entity_type == 'commerce_order' && $field_name == 'order_items';
}
}
Classes
Name |
Description |
OrderItemTable |
Plugin implementation of the 'commerce_order_item_table' formatter. |