InstagramAccountListBuilder.php in Instagram Feeds 8
File
src/InstagramAccountListBuilder.php
View source
<?php
namespace Drupal\instagram_feeds;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\user\EntityOwnerInterface;
class InstagramAccountListBuilder extends EntityListBuilder {
protected $dateFormatterService;
protected function getColumns() {
return [
'iid' => $this
->t('Instagram User ID'),
'account' => $this
->t('Instagram Username'),
'cron_import_limit' => $this
->t('Cron Import Limit'),
'media_bundle' => $this
->t('Media Type'),
'status' => $this
->t('Status'),
'token_expiration' => $this
->t('Token Expiry'),
'uid' => $this
->t('Author'),
];
}
public function buildHeader() {
$header = [];
foreach ($this
->getColumns() as $field => $label) {
$header[$field] = [
'data' => $label,
'field' => $field,
'specifier' => $field,
];
}
$header['iid']['class'] = [
RESPONSIVE_PRIORITY_LOW,
];
$header['media_bundle']['class'] = [
RESPONSIVE_PRIORITY_LOW,
];
$header['cron_import_limit']['class'] = [
RESPONSIVE_PRIORITY_LOW,
];
$header['token_expiration']['sort'] = 'desc';
return $header + parent::buildHeader();
}
protected function dateFormatter() : DateFormatterInterface {
if (!isset($this->dateFormatterService)) {
$this->dateFormatterService = \Drupal::service('date.formatter');
}
return $this->dateFormatterService;
}
public function buildRow(EntityInterface $entity) {
$row = [];
foreach (array_keys($this
->getColumns()) as $field) {
$value = $entity
->get($field)
->first()
->getValue();
$row[$field]['data']['#markup'] = reset($value);
}
$row['uid']['data'] = [
'#theme' => 'username',
'#account' => $entity
->getOwner(),
];
$row['account'] = $entity
->toLink();
$row['status'] = empty($row['status']) ? $this
->t('Disabled') : $this
->t('Enabled');
$row['token_expiration']['data'] = $this
->dateFormatter()
->format($entity
->getTokenExpirationTime(), 'short');
return $row + parent::buildRow($entity);
}
}