You are here

StockLocationListBuilder.php in Commerce Stock 8

File

modules/local_storage/src/StockLocationListBuilder.php
View source
<?php

namespace Drupal\commerce_stock_local;

use Drupal\commerce_stock_local\Entity\StockLocationType;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;

/**
 * Defines a class to build a listing of stock location entities.
 *
 * @ingroup commerce_stock_local
 */
class StockLocationListBuilder extends EntityListBuilder {

  /**
   * {@inheritdoc}
   */
  public function buildHeader() {
    $header['id'] = $this
      ->t('Location ID');
    $header['name'] = $this
      ->t('Name');
    $header['type'] = $this
      ->t('Type');
    $header['status'] = $this
      ->t('Status');
    return $header + parent::buildHeader();
  }

  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity) {

    /** @var \Drupal\commerce_stock_local\Entity\StockLocationType $location_type */
    $location_type = StockLocationType::load($entity
      ->bundle());
    $row['id'] = $entity
      ->id();
    $row['name']['data'] = [
      '#type' => 'link',
      '#title' => $entity
        ->label(),
    ] + $entity
      ->toUrl()
      ->toRenderArray();
    $row['type'] = $location_type
      ->label();
    $row['status'] = $entity
      ->isActive() ? $this
      ->t('Active') : $this
      ->t('Inactive');
    return $row + parent::buildRow($entity);
  }

}

Classes

Namesort descending Description
StockLocationListBuilder Defines a class to build a listing of stock location entities.