You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
3.2 KiB
124 lines
3.2 KiB
3 years ago
|
<?php
|
||
|
|
||
|
namespace Drupal\dgi_fixity;
|
||
|
|
||
|
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\Core\Render\RendererInterface;
|
||
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||
|
|
||
|
/**
|
||
|
* Provides a listing of fixity check items.
|
||
|
*/
|
||
|
class FixityCheckListBuilder extends EntityListBuilder {
|
||
|
|
||
|
/**
|
||
|
* The date formatter service.
|
||
|
*
|
||
|
* @var \Drupal\Core\Datetime\DateFormatterInterface
|
||
|
*/
|
||
|
protected $dateFormatter;
|
||
|
|
||
|
/**
|
||
|
* The renderer service.
|
||
|
*
|
||
|
* @var \Drupal\Core\Render\RendererInterface
|
||
|
*/
|
||
|
protected $renderer;
|
||
|
|
||
|
/**
|
||
|
* Constructs a new FixityCheckListBuilder object.
|
||
|
*
|
||
|
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
|
||
|
* The entity type definition.
|
||
|
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
|
||
|
* The entity storage class.
|
||
|
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
|
||
|
* The date formatter service.
|
||
|
* @param \Drupal\Core\Render\RendererInterface $renderer
|
||
|
* The renderer service.
|
||
|
*/
|
||
|
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, DateFormatterInterface $date_formatter, RendererInterface $renderer) {
|
||
|
parent::__construct($entity_type, $storage);
|
||
|
$this->dateFormatter = $date_formatter;
|
||
|
$this->renderer = $renderer;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* {@inheritdoc}
|
||
|
*/
|
||
|
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
|
||
|
$entity_type_manager = $container->get('entity_type.manager');
|
||
|
return new static(
|
||
|
$entity_type,
|
||
|
$entity_type_manager->getStorage($entity_type->id()),
|
||
|
$container->get('date.formatter'),
|
||
|
$container->get('renderer'),
|
||
|
);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* {@inheritdoc}
|
||
|
*/
|
||
|
public function buildHeader() {
|
||
|
$header = [];
|
||
|
$header += [
|
||
|
'link' => [
|
||
|
'data' => $this->t('Check'),
|
||
|
],
|
||
|
'state' => [
|
||
|
'data' => $this->t('State'),
|
||
|
],
|
||
|
'performed' => [
|
||
|
'data' => $this->t('Performed'),
|
||
|
],
|
||
|
];
|
||
|
return $header + parent::buildHeader();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* {@inheritdoc}
|
||
|
*/
|
||
|
public function buildRow(EntityInterface $entity) {
|
||
|
/** @var \Drupal\dgi_fixity\FixityCheckInterface $entity */
|
||
|
$row = [
|
||
|
'link' => $entity->toLink(),
|
||
|
];
|
||
|
|
||
|
$row['state']['data'] = $entity->state->view([
|
||
|
'label' => 'hidden',
|
||
|
'type' => 'dgi_fixity_state',
|
||
|
]);
|
||
|
|
||
|
// Use timestamp rather than timestamp_ago to allow for caching.
|
||
|
$row['performed']['data'] = $entity->wasPerformed() ?
|
||
|
$entity->performed->view([
|
||
|
'label' => 'hidden',
|
||
|
'type' => 'timestamp',
|
||
|
'weight' => 1,
|
||
|
]) :
|
||
|
['#markup' => $this->t('never')];
|
||
|
|
||
|
return $row + parent::buildRow($entity);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* {@inheritdoc}
|
||
|
*/
|
||
|
protected function getEntityIds() {
|
||
|
$query = $this->getStorage()->getQuery()
|
||
|
->accessCheck(TRUE)
|
||
|
->sort('performed', 'DESC');
|
||
|
|
||
|
// Only add the pager if a limit is specified.
|
||
|
if ($this->limit) {
|
||
|
$query->pager($this->limit);
|
||
|
}
|
||
|
return $query->execute();
|
||
|
}
|
||
|
|
||
|
}
|