Skip to content
Snippets Groups Projects

Fix Date being hardcode to American date and time format

1 file
+ 16
4
Compare changes
  • Side-by-side
  • Inline
@@ -7,6 +7,7 @@ use Drupal\Core\Entity\EntityViewBuilderInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Session\AccountProxy;
use Drupal\user\UserStorageInterface;
use Drupal\taxonomy\TermStorageInterface;
@@ -61,16 +62,24 @@ class TermRevisionController extends ControllerBase {
*/
protected $termViewBuilder;
/**
* The date formatter service.
*
* @var \Drupal\Core\Datetime\DateFormatterInterface
*/
protected $dateFormatter;
/**
* {@inheritdoc}
*/
public function __construct(Connection $database, AccountProxy $current_user, UserStorageInterface $user_storage, TermStorageInterface $term_storage, EntityRepository $entity_repository, EntityViewBuilderInterface $term_view_builder) {
public function __construct(Connection $database, AccountProxy $current_user, UserStorageInterface $user_storage, TermStorageInterface $term_storage, EntityRepository $entity_repository, EntityViewBuilderInterface $term_view_builder, DateFormatterInterface $date_formatter) {
$this->database = $database;
$this->currentUser = $current_user;
$this->userStorage = $user_storage;
$this->termManager = $term_storage;
$this->entityRepository = $entity_repository;
$this->termViewBuilder = $term_view_builder;
$this->dateFormatter = $date_formatter;
}
/**
@@ -83,7 +92,8 @@ class TermRevisionController extends ControllerBase {
$container->get('entity_type.manager')->getStorage('user'),
$container->get('entity_type.manager')->getStorage('taxonomy_term'),
$container->get('entity.repository'),
$container->get('entity_type.manager')->getViewBuilder('taxonomy_term')
$container->get('entity_type.manager')->getViewBuilder('taxonomy_term'),
$container->get('date.formatter')
);
}
@@ -133,9 +143,11 @@ class TermRevisionController extends ControllerBase {
// Check if Current revision.
$term = $this->termManager->loadRevision($result->revision_id);
$date = $this->dateFormatter->format($result->revision_created, 'short');
if ($term->isDefaultRevision()) {
$data[$index] = [
Link::fromTextAndUrl(date('m/d/Y H:i:s', $result->revision_created), Url::fromUri('internal:/taxonomy/term/' . $taxonomy_term->id())),
Link::fromTextAndUrl($date, Url::fromUri('internal:/taxonomy/term/' . $taxonomy_term->id())),
$revision_user,
$this->t('Current Revision'),
$result->revision_log_message,
@@ -156,7 +168,7 @@ class TermRevisionController extends ControllerBase {
'id' => $result->revision_id,
]))->toString() : '';
$data[$index] = [
Link::fromTextAndUrl(date('m/d/Y H:i:s', $result->revision_created), Url::fromRoute('taxonomy_term_revision.view', [
Link::fromTextAndUrl($date, Url::fromRoute('taxonomy_term_revision.view', [
'taxonomy_term' => $taxonomy_term->id(),
'revision_id' => $result->revision_id,
])),
Loading