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(); } }