GatsbyLogEntityListBuilder.php in Gatsby Live Preview & Incremental Builds 8
File
modules/gatsby_fastbuilds/src/GatsbyLogEntityListBuilder.php
View source
<?php
namespace Drupal\gatsby_fastbuilds;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\gatsby_fastbuilds\Entity\GatsbyLogEntity;
use Symfony\Component\DependencyInjection\ContainerInterface;
class GatsbyLogEntityListBuilder extends EntityListBuilder {
protected $dateFormatter;
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
$instance = parent::createInstance($container, $entity_type);
$instance->dateFormatter = $container
->get('date.formatter');
return $instance;
}
protected function getEntityIds() {
$query = $this
->getStorage()
->getQuery()
->sort('created', 'DESC');
if ($this->limit) {
$query
->pager($this->limit);
}
return $query
->execute();
}
public function buildHeader() {
$header['id'] = $this
->t('ID');
$header['title'] = $this
->t('Entity Title');
$header['entity_uuid'] = $this
->t('Entity UUID');
$header['entity'] = $this
->t('Entity Type');
$header['bundle'] = $this
->t('Bundle');
$header['langcode'] = $this
->t('Language');
$header['action'] = $this
->t('Action');
$header['created'] = $this
->t('Log Entry Created');
return $header;
}
public function buildRow(EntityInterface $entity) {
if (!$entity instanceof GatsbyLogEntity) {
return parent::buildRow($entity);
}
$row['id'] = $entity
->id();
$row['title'] = $entity
->getTitle();
$row['entity_uuid'] = $entity
->get('entity_uuid')->value;
$row['entity'] = $entity
->get('entity')->value;
$row['bundle'] = $entity
->get('bundle')->value;
$row['langcode'] = $entity
->get('langcode')->value;
$row['action'] = $entity
->get('action')->value;
$row['created'] = $this->dateFormatter
->format($entity
->getCreatedTime());
return $row;
}
}