EasyEmailListBuilder.php in Easy Email 2.0.x
File
src/EasyEmailListBuilder.php
View source
<?php
namespace Drupal\easy_email;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Link;
class EasyEmailListBuilder extends EntityListBuilder {
protected function getEntityIds() {
$query = $this
->getStorage()
->getQuery()
->sort($this->entityType
->getKey('id'), 'DESC');
if ($this->limit) {
$query
->pager($this->limit);
}
return $query
->execute();
}
public function buildHeader() {
$header['id'] = $this
->t('ID');
$header['type'] = $this
->t('Type');
$header['recipient'] = $this
->t('Recipient');
$header['created'] = $this
->t('Created');
$header['sent'] = $this
->t('Sent');
$header['status'] = $this
->t('Status');
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$types = array_map(function ($type) {
return $type
->label();
}, $this
->getStorage()
->getEmailTypeStorage()
->loadMultiple());
$row['id'] = Link::createFromRoute($entity
->id(), 'entity.easy_email.canonical', [
'easy_email' => $entity
->id(),
]);
$row['type'] = !empty($types[$entity
->bundle()]) ? $types[$entity
->bundle()] : '';
$recipients = $entity
->getRecipientAddresses();
$row['recipient'] = !empty($recipients) ? implode(', ', $recipients) : '';
$date_formatter = \Drupal::service('date.formatter');
$row['created'] = $date_formatter
->format($entity
->getCreatedTime(), 'short');
$row['sent'] = $entity
->isSent() ? $date_formatter
->format($entity
->getSentTime(), 'short') : '';
$row['status'] = $entity
->isSent() ? $this
->t('Sent') : $this
->t('Unsent');
return $row + parent::buildRow($entity);
}
protected function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
$operations['view'] = [
'title' => $this
->t('View'),
'weight' => -10,
'url' => $this
->ensureDestination($entity
->toUrl('canonical')),
];
return $operations;
}
}