You are here

public function EasyEmailListBuilder::buildRow in Easy Email 8

Same name and namespace in other branches
  1. 2.0.x src/EasyEmailListBuilder.php \Drupal\easy_email\EasyEmailListBuilder::buildRow()

Builds a row for an entity in the entity listing.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for this row of the list.

Return value

array A render array structure of fields for this entity.

Overrides EntityListBuilder::buildRow

See also

\Drupal\Core\Entity\EntityListBuilder::render()

File

src/EasyEmailListBuilder.php, line 48

Class

EasyEmailListBuilder
Defines a class to build a listing of Email entities.

Namespace

Drupal\easy_email

Code

public function buildRow(EntityInterface $entity) {
  $types = array_map(function ($type) {
    return $type
      ->label();
  }, $this
    ->getStorage()
    ->getEmailTypeStorage()
    ->loadMultiple());

  /* @var $entity \Drupal\easy_email\Entity\EasyEmail */
  $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) : '';

  /** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
  $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);
}