SearchEngineListBuilder.php in Simple XML sitemap 4.x
File
modules/simple_sitemap_engines/src/Controller/SearchEngineListBuilder.php
View source
<?php
namespace Drupal\simple_sitemap_engines\Controller;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\State\StateInterface;
use Drupal\simple_sitemap\Form\FormHelper;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SearchEngineListBuilder extends ConfigEntityListBuilder {
protected $dateFormatter;
protected $state;
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, DateFormatterInterface $date_formatter, StateInterface $state) {
parent::__construct($entity_type, $storage);
$this->dateFormatter = $date_formatter;
$this->state = $state;
}
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($entity_type, $container
->get('entity_type.manager')
->getStorage($entity_type
->id()), $container
->get('date.formatter'), $container
->get('state'));
}
public function buildHeader() {
$header['label'] = $this
->t('Name');
$header['url'] = $this
->t('Submission URL');
$header['variants'] = $this
->t('Sitemap variants');
$header['last_submitted'] = $this
->t('Last submitted');
return $header;
}
public function buildRow(EntityInterface $entity) {
$last_submitted = $this->state
->get("simple_sitemap_engines.simple_sitemap_engine.{$entity->id()}.last_submitted", -1);
$row['label'] = $entity
->label();
$row['url'] = $entity->url;
$row['variants'] = implode(', ', $entity->sitemap_variants);
$row['last_submitted'] = $last_submitted !== -1 ? $this->dateFormatter
->format($last_submitted, 'short') : $this
->t('Never');
return $row;
}
public function render() {
return [
'simple_sitemap_engines' => [
'#type' => 'details',
'#open' => TRUE,
'#prefix' => FormHelper::getDonationText(),
'#title' => $this
->t('Submission status'),
'table' => parent::render(),
'#description' => $this
->t('Submission settings can be configured <a href="@url">here</a>.', [
'@url' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap/engines/settings',
]),
],
];
}
}