You are here

public function EntityBundle::getItems in Commerce Core 8.2

Gets an array of items for the field.

Parameters

\Drupal\views\ResultRow $values: The result row object containing the values.

Return value

array An array of items for the field.

Overrides EntityField::getItems

File

src/Plugin/views/field/EntityBundle.php, line 126

Class

EntityBundle
Displays the entity bundle.

Namespace

Drupal\commerce\Plugin\views\field

Code

public function getItems(ResultRow $values) {
  $items = parent::getItems($values);

  // Show the bundle label for entity types which don't use a bundle
  // entity type (i.e. they use bundle plugins).
  $entity_type_id = $this
    ->getEntityType();
  $entity_type = $this->entityTypeManager
    ->getDefinition($entity_type_id);
  if (!$entity_type
    ->getBundleEntityType()) {
    $bundles = $this->entityTypeBundleInfo
      ->getBundleInfo($entity_type_id);
    foreach ($items as &$item) {
      $bundle = $item['raw']
        ->get('value')
        ->getValue();
      if (isset($bundles[$bundle])) {
        $item['rendered']['#context']['value'] = $bundles[$bundle]['label'];
      }
    }
  }
  return $items;
}