You are here

public function SubscriptionListBuilder::buildRow in Mailing List 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/SubscriptionListBuilder.php, line 110

Class

SubscriptionListBuilder
Defines a class to build a listing of subscriptions.

Namespace

Drupal\mailing_list

Code

public function buildRow(EntityInterface $entity) {
  $row = [];

  /** @var \Drupal\mailing_list\SubscriptionInterface $entity */
  if (!$entity
    ->access('view')) {
    return $row;
  }
  $uri = $entity
    ->urlInfo();
  $options = $uri
    ->getOptions();
  $langcode = $entity
    ->language()
    ->getId();
  $languages = \Drupal::languageManager()
    ->getLanguages();
  $options += $langcode != LanguageInterface::LANGCODE_NOT_SPECIFIED && isset($languages[$langcode]) ? [
    'language' => $languages[$langcode],
  ] : [];
  $uri
    ->setOptions($options);
  $row['title']['data'] = [
    '#type' => 'link',
    '#title' => $entity
      ->label(),
    '#url' => $uri,
  ];
  $row['list'] = $entity
    ->getList()
    ->label();
  $row['email']['data'] = [
    '#markup' => $entity
      ->getEmail(),
  ];
  if ($this->currentUser
    ->hasPermission('administer mailing list subscriptions')) {
    $row['author']['data'] = [
      '#theme' => 'username',
      '#account' => $entity
        ->getOwner(),
    ];
    $row['status'] = $entity
      ->isActive() ? $this
      ->t('Active') : $this
      ->t('Inactive');
    $row['changed'] = \Drupal::service('date.formatter')
      ->format($entity
      ->getChangedTime(), 'short');
  }
  return $row + parent::buildRow($entity);
}