<?php

namespace Drupal\edlp_studio;

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Link;

/**
 * Defines a class to build a listing of Chutier entities.
 *
 * @ingroup edlp_studio
 */
class ChutierListBuilder extends EntityListBuilder {


  /**
   * {@inheritdoc}
   */
  public function buildHeader() {
    $header['id'] = $this->t('Chutier ID');
    $header['name'] = $this->t('Name');
    $header['user'] = $this->t('User');
    // $header['default'] = $this->t('User id');
    return $header + parent::buildHeader();
  }

  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity) {
    /* @var $entity \Drupal\edlp_studio\Entity\Chutier */
    $row['id'] = $entity->id();
    $row['name'] = Link::createFromRoute(
      $entity->label(),
      'entity.chutier.edit_form',
      ['chutier' => $entity->id()]
    );
    $row['user'] = Link::createFromRoute(
      $entity->getOwner()->getUserName(),
      'entity.user.canonical',
      ['user' => $entity->getOwnerId()]
    );

    // $row['uid'] = $entity->getOwnerId();
    return $row + parent::buildRow($entity);
  }

}
