You are here

public function ReplicationListBuilder::buildRow in Deploy - Content Staging 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/ReplicationListBuilder.php, line 41

Class

ReplicationListBuilder
Defines a class to build a listing of Replication entities.

Namespace

Drupal\deploy

Code

public function buildRow(EntityInterface $entity) {
  $formatter = \Drupal::service('date.formatter');

  /* @var $entity \Drupal\workspace\Entity\Replication */
  $row['replication_status'] = $this
    ->getReplicationStatusIcon($entity
    ->getReplicationStatus(), $entity
    ->id());
  $row['name'] = $entity
    ->label();
  $row['source'] = $entity
    ->get('source')->entity ? $entity
    ->get('source')->entity
    ->label() : $this
    ->t('<em>Unknown</em>');
  $row['target'] = $entity
    ->get('target')->entity ? $entity
    ->get('target')->entity
    ->label() : $this
    ->t('<em>Unknown</em>');
  $user = User::load($entity->uid->target_id);
  $row['changed'] = $formatter
    ->format($entity
    ->getChangedTime());
  $row['created'] = $formatter
    ->format($entity
    ->getCreatedTime());
  $row['user'] = $user
    ->getAccountName();
  $row['description'] = $entity->description->value;

  // Set operations.
  $links = [];
  if ($entity
    ->hasLinkTemplate('delete-form') && in_array($entity
    ->getReplicationStatus(), [
    Replication::REPLICATED,
    Replication::FAILED,
  ])) {
    $links['delete'] = [
      'title' => t('Delete'),
      'url' => $entity
        ->toUrl('delete-form', [
        'absolute' => TRUE,
      ]),
    ];
  }
  $row[] = [
    'data' => [
      '#type' => 'operations',
      '#links' => $links,
    ],
  ];
  return $row;
}