SmartDateFormatListBuilder.php in Smart Date 3.4.x
File
src/Entity/SmartDateFormatListBuilder.php
View source
<?php
namespace Drupal\smart_date\Entity;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Link;
use Drupal\smart_date\SmartDateTrait;
class SmartDateFormatListBuilder extends EntityListBuilder {
public function buildHeader() {
$header['name'] = $this
->t('Name');
$header['preview'] = $this
->t('Preview');
$header['date_format'] = $this
->t('Date Format');
$header['time_format'] = $this
->t('Time Format');
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$row['query'] = Link::createFromRoute($entity
->label(), 'entity.smart_date_format.edit_form', [
'smart_date_format' => $entity
->id(),
]);
$formatted = SmartDateTrait::formatSmartDate(time(), time() + 3600, $entity
->getOptions(), NULL, 'string');
$row['preview']['data'] = $formatted;
$row['date_format']['data'] = $entity
->get('date_format');
$row['time_format']['data'] = $entity
->get('time_format');
return $row + parent::buildRow($entity);
}
protected function makeLinksFromRef($ref) {
if (!$ref) {
return NULL;
}
$entities = $ref
->referencedEntities();
$content = [
'#theme' => 'item_list',
'#list_type' => 'ul',
'#wrapper_attributes' => [
'class' => 'container',
],
];
$links = [];
foreach ($entities as $ref_entity) {
$links[] = Link::fromTextAndUrl($ref_entity
->getTitle(), $ref_entity
->toUrl());
}
$content['#items'] = $links;
return $content;
}
}