PathFileEntityListBuilder.php in Path File 8
File
src/PathFileEntityListBuilder.php
View source
<?php
namespace Drupal\path_file;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class PathFileEntityListBuilder extends EntityListBuilder {
protected $dateFormatter;
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, DateFormatterInterface $date_formatter) {
parent::__construct($entity_type, $storage);
$this->dateFormatter = $date_formatter;
}
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($entity_type, $container
->get('entity_type.manager')
->getStorage($entity_type
->id()), $container
->get('date.formatter'));
}
public function buildHeader() {
$header = array(
'name' => $this
->t('Name'),
'url' => array(
'data' => $this
->t('File Url'),
'class' => array(
RESPONSIVE_PRIORITY_MEDIUM,
),
),
'status' => $this
->t('Status'),
'changed' => array(
'data' => $this
->t('Updated'),
'class' => array(
RESPONSIVE_PRIORITY_LOW,
),
),
);
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$row['name'] = $entity
->toLink(NULL, 'edit-form');
$row['url'] = $entity
->toLink($entity
->toUrl()
->toString());
$row['status'] = $entity
->isPublished() ? $this
->t('published') : $this
->t('not published');
$row['changed'] = $this->dateFormatter
->format($entity
->getChangedTime(), 'short');
return $row + parent::buildRow($entity);
}
}