You are here

public function PackageTypeListBuilder::buildRow in Commerce Shipping 8.2

Builds a row for an entity in the entity listing.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for this row of the list.

Return value

array A render array structure of fields for this entity.

Overrides EntityListBuilder::buildRow

See also

\Drupal\Core\Entity\EntityListBuilder::render()

File

src/PackageTypeListBuilder.php, line 64

Class

PackageTypeListBuilder
Provides a listing of package types.

Namespace

Drupal\commerce_shipping

Code

public function buildRow(EntityInterface $entity) {

  /** @var \Drupal\commerce_shipping\Entity\PackageTypeInterface $entity */
  $row['label'] = $entity
    ->label();
  $dimensions = $entity
    ->getDimensions();
  $dimension_list = [
    $this->numberFormatter
      ->format($dimensions['length']),
    $this->numberFormatter
      ->format($dimensions['width']),
    $this->numberFormatter
      ->format($dimensions['height']),
  ];
  $row['dimensions'] = implode(' × ', $dimension_list) . ' ' . $dimensions['unit'];
  $weight = $entity
    ->getWeight();
  $row['weight'] = $this->numberFormatter
    ->format($weight['number']) . ' ' . $weight['unit'];
  return $row + parent::buildRow($entity);
}