ILTListBuilder.php in Opigno Instructor-led Trainings 3.x
File
src/ILTListBuilder.php
View source
<?php
namespace Drupal\opigno_ilt;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Url;
class ILTListBuilder extends EntityListBuilder {
public function buildHeader() {
$header['id'] = $this
->t('ID');
$header['name'] = $this
->t('Name');
$header['training'] = $this
->t('Related training');
$header['date'] = $this
->t('Date');
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$row['id'] = $entity
->id();
$row['name'] = $entity
->toLink();
$training = $entity
->getTraining();
$row['training'] = isset($training) ? $entity
->getTraining()
->toLink() : '-';
$date = $entity
->getStartDate();
$row['date'] = !empty($date) ? $date : '-';
return $row + parent::buildRow($entity);
}
public function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
$operations['score'] = [
'title' => $this
->t('Score'),
'weight' => 10,
'url' => Url::fromRoute('opigno_ilt.score', [
'opigno_ilt' => $entity
->id(),
], [
'query' => [
'destination' => 'admin/content/ilt',
],
'absolute' => TRUE,
]),
];
return $operations;
}
}