You are here

public function MessageListBuilder::buildRow in Mass Contact 8

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/MessageListBuilder.php, line 79

Class

MessageListBuilder
Mass contact message archive list builder.

Namespace

Drupal\mass_contact

Code

public function buildRow(EntityInterface $entity) {

  // Build a list of categories.
  $categories = [];
  foreach ($entity
    ->getCategories() as $category) {

    // It is possible to delete a category after creating a mass contact
    // message for that category.
    if (!empty($category)) {
      $categories[] = $category
        ->label();
    }
  }

  /** @var \Drupal\mass_contact\Entity\MassContactMessageInterface $entity */
  $row = [
    'subject' => $entity
      ->toLink(),
    'sent' => $this->dateFormatter
      ->format($entity
      ->getSentTime(), 'short'),
    'uid' => $entity
      ->getOwner()
      ->toLink(),
    'categories' => [
      'data' => [
        '#theme' => 'item_list',
        '#items' => $categories,
      ],
    ],
  ];
  $row += parent::buildRow($entity);
  return $row;
}