commerce-8.x-2.8/modules/order/src/Plugin/Field/FieldFormatter/OrderItemTable.php
modules/order/src/Plugin/Field/FieldFormatter/OrderItemTable.php
<?php
namespace Drupal\commerce_order\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
/**
* Plugin implementation of the 'commerce_order_item_table' formatter.
*
* @FieldFormatter(
* id = "commerce_order_item_table",
* label = @Translation("Order item table"),
* field_types = {
* "entity_reference",
* },
* )
*/
class OrderItemTable extends FormatterBase {
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
/** @var \Drupal\commerce_order\Entity\OrderInterface $order */
$order = $items->getEntity();
$elements = [];
$elements[0] = [
'#type' => 'view',
// @todo Allow the view to be configurable.
'#name' => 'commerce_order_item_table',
'#arguments' => [$order->id()],
'#embed' => TRUE,
];
return $elements;
}
/**
* {@inheritdoc}
*/
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';
}
}
