PollListBuilder.php in Poll 8
File
src/PollListBuilder.php
View source
<?php
namespace Drupal\poll;
use Drupal;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Config\Entity\DraggableListBuilder;
class PollListBuilder extends DraggableListBuilder {
public function load() {
$entities = $this->storage
->loadMultiple();
uasort($entities, array(
$this->entityType
->getClass(),
'sort',
));
return $entities;
}
public function getFormId() {
return 'poll_list_form';
}
public function buildHeader() {
$header['question'] = t('Question');
$header['author'] = t('Author');
$header['votes'] = t('Votes');
$header['status'] = t('Status');
$header['created'] = t('Created');
$header['operations'] = t('Operations');
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$vote_storage = \Drupal::service('poll_vote.storage');
$row['question'] = $entity
->toLink()
->toString();
$row['author']['data'] = array(
'#theme' => 'username',
'#account' => $entity
->getOwner(),
);
$row['status'] = $entity
->isOpen() ? t('Y') : t('N');
$row['created'] = $entity
->getCreated() ? Drupal::service('date.formatter')
->format($entity
->getCreated(), 'long') : t('n/a');
return $row + parent::buildRow($entity);
}
public function getOperations(EntityInterface $entity) {
$operations = parent::getOperations($entity);
return $operations;
}
}