Skip to content
Snippets Groups Projects
Commit d604dfa4 authored by narendra.desai's avatar narendra.desai
Browse files

Using generic short date format.

parent 4ff5c295
Branches
Tags
No related merge requests found
......@@ -5,13 +5,13 @@ namespace Drupal\taxonomy_term_revision\Controller;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Database\Connection;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Entity\EntityRepository;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityViewBuilderInterface;
use Drupal\Core\GeneratedLink;
use Drupal\Core\Link;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountProxy;
use Drupal\Core\Url;
use Drupal\taxonomy\TermInterface;
use Drupal\taxonomy\TermStorageInterface;
......@@ -55,13 +55,6 @@ class TermRevisionController extends ControllerBase {
*/
protected Connection $database;
/**
* Drupal\Core\Session\AccountProxy definition.
*
* @var \Drupal\Core\Session\AccountProxy
*/
protected $currentUser;
/**
* The user storage details connection.
*
......@@ -90,16 +83,23 @@ class TermRevisionController extends ControllerBase {
*/
protected EntityViewBuilderInterface $termViewBuilder;
/**
* The date formatter.
*
* @var \Drupal\Core\Datetime\DateFormatterInterface
*/
protected DateFormatterInterface $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, 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;
}
/**
......@@ -108,11 +108,11 @@ class TermRevisionController extends ControllerBase {
public static function create(ContainerInterface $container) {
return new static(
$container->get('database'),
$container->get('current_user'),
$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')
);
}
......@@ -157,25 +157,26 @@ 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,
];
}
else {
$revert_link = $this->currentUser->hasPermission(self::REVERT_TERM_REVISION_PERMISSION) ? $this->getLink(self::REVERT, $taxonomy_term->id(), $result->revision_id) : '';
$delete_link = $this->currentUser->hasPermission(self::DELETE_TERM_REVISION_PERMISSION) ? $this->getLink(self::DELETE, $taxonomy_term->id(), $result->revision_id) : '';
$revert_link = $this->currentUser()->hasPermission(self::REVERT_TERM_REVISION_PERMISSION) ? $this->getLink(self::REVERT, $taxonomy_term->id(), $result->revision_id) : '';
$delete_link = $this->currentUser()->hasPermission(self::DELETE_TERM_REVISION_PERMISSION) ? $this->getLink(self::DELETE, $taxonomy_term->id(), $result->revision_id) : '';
$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,
])),
$revision_user,
$this->t('@revert @delete', [
$this->t('@revert | @delete', [
'@revert' => $revert_link,
'@delete' => $delete_link,
]),
......
entity.taxonomy_term.revisions:
title: 'Revisionzzs'
title: 'Revisions'
route_name: taxonomy_term_revision.all
base_route: entity.taxonomy_term.canonical
taxonomy_term_revision.all:
path: '/taxonomy/term/{taxonomy_term}/revisionzzs'
path: '/taxonomy/term/{taxonomy_term}/revisions'
defaults:
_controller: '\Drupal\taxonomy_term_revision\Controller\TermRevisionController::getRevisions'
_title: 'Revisions'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment