UserConsentListBuilder.php in Data Policy 8
File
src/UserConsentListBuilder.php
View source
<?php
namespace Drupal\data_policy;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\user\UserInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class UserConsentListBuilder extends EntityListBuilder {
protected $dateFormatter;
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, DateFormatterInterface $date_formatter) {
parent::__construct($entity_type, $storage);
$this->dateFormatter = $date_formatter;
}
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($entity_type, $container
->get('entity.manager')
->getStorage($entity_type
->id()), $container
->get('date.formatter'));
}
public function buildHeader() {
return [
'id' => $this
->t('ID'),
'user' => $this
->t('User'),
'created' => $this
->t('Date and time of consent'),
];
}
public function buildRow(EntityInterface $entity) {
$owner = $entity
->getOwner();
return [
'id' => $entity
->id(),
'user' => $owner instanceof UserInterface ? $owner
->getDisplayName() : $this
->t('Deleted user'),
'created' => $this->dateFormatter
->format($entity
->getChangedTime(), 'short'),
];
}
}