page_layouts-1.0.1/src/LayoutListBuilder.php
src/LayoutListBuilder.php
<?php
declare(strict_types=1);
namespace Drupal\page_layouts;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
/**
* Provides a list controller for the layout entity type.
*/
final class LayoutListBuilder extends EntityListBuilder {
/**
* {@inheritdoc}
*/
public function buildHeader(): array {
$header['id'] = $this->t('ID');
$header['label'] = $this->t('Label');
$header['layout'] = $this->t('Layout');
$header['status'] = $this->t('Status');
$header['weight'] = $this->t('Weight');
$header['uid'] = $this->t('Author');
$header['changed'] = $this->t('Updated');
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity): array {
/** @var \Drupal\page_layouts\LayoutInterface $entity */
$row['id'] = $entity->id();
$row['label'] = $entity->toLink();
$row['layout'] = $entity->get('layout')->value;
$row['status'] = $entity->get('status')->value ? $this->t('Enabled') : $this->t('Disabled');
$username_options = [
'label' => 'hidden',
'settings' => ['link' => $entity->get('uid')->entity->isAuthenticated()],
];
$row['weight'] = $entity->get('weight')->value;
$row['uid']['data'] = $entity->get('uid')->view($username_options);
$row['changed']['data'] = $entity->get('changed')->view(['label' => 'hidden']);
return $row + parent::buildRow($entity);
}
}
