Commit 5783e08f authored by alexpott's avatar alexpott

Issue #2149197 by penyaskito, mikey_p, vijaycs85, herom: Replace...

Issue #2149197 by penyaskito, mikey_p, vijaycs85, herom: Replace format_interval with \Drupal::service('date')->formatInterval().
parent 0872feb1
......@@ -319,9 +319,9 @@ function _batch_process() {
'@total' => $total,
'@current' => floor($current),
'@percentage' => $percentage,
'@elapsed' => format_interval($elapsed / 1000),
'@elapsed' => \Drupal::service('date')->formatInterval($elapsed / 1000),
// If possible, estimate remaining processing time.
'@estimate' => ($current > 0) ? format_interval(($elapsed * ($total - $current) / $current) / 1000) : '-',
'@estimate' => ($current > 0) ? \Drupal::service('date')->formatInterval(($elapsed * ($total - $current) / $current) / 1000) : '-',
);
$message = strtr($progress_message, $values);
if (!empty($task_message)) {
......@@ -410,7 +410,7 @@ function _batch_finished() {
if (is_callable($batch_set['finished'])) {
$queue = _batch_queue($batch_set);
$operations = $queue->getAllItems();
call_user_func_array($batch_set['finished'], array($batch_set['success'], $batch_set['results'], $operations, format_interval($batch_set['elapsed'] / 1000)));
call_user_func_array($batch_set['finished'], array($batch_set['success'], $batch_set['results'], $operations, \Drupal::service('date')->formatInterval($batch_set['elapsed'] / 1000)));
}
}
}
......
......@@ -33,7 +33,7 @@ function template_preprocess_aggregator_item(&$variables) {
$variables['source_title'] = String::checkPlain($item->ftitle);
}
if (date('Ymd', $item->getPostedTime()) == date('Ymd')) {
$variables['source_date'] = t('%ago ago', array('%ago' => format_interval(REQUEST_TIME - $item->getPostedTime())));
$variables['source_date'] = t('%ago ago', array('%ago' => \Drupal::service('date')->formatInterval(REQUEST_TIME - $item->getPostedTime())));
}
else {
$variables['source_date'] = format_date($item->getPostedTime(), 'medium');
......@@ -121,7 +121,7 @@ function template_preprocess_aggregator_summary_item(&$variables) {
'datetime' => format_date($item->getPostedTime(), 'html_datetime', '', 'UTC'),
'class' => array('feed-item-age',),
),
'#text' => t('%age old', array('%age' => format_interval(REQUEST_TIME - $item->getPostedTime()))),
'#text' => t('%age old', array('%age' => \Drupal::service('date')->formatInterval(REQUEST_TIME - $item->getPostedTime()))),
'#html' => TRUE,
);
}
......@@ -161,7 +161,7 @@ function template_preprocess_aggregator_feed_source(&$variables) {
$variables['source_url'] = check_url(url($feed->getWebsiteUrl(), array('absolute' => TRUE)));
if ($feed->checked) {
$variables['last_checked'] = t('@time ago', array('@time' => format_interval(REQUEST_TIME - $feed->getLastCheckedTime())));
$variables['last_checked'] = t('@time ago', array('@time' => \Drupal::service('date')->formatInterval(REQUEST_TIME - $feed->getLastCheckedTime())));
}
else {
$variables['last_checked'] = t('never');
......
......@@ -9,15 +9,43 @@
use Drupal\Component\Utility\Xss;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Datetime\Date as DateFormatter;
use Drupal\aggregator\FeedInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Returns responses for aggregator module routes.
*/
class AggregatorController extends ControllerBase {
/**
* The date formatter service.
*
* @var \Drupal\Core\Datetime\Date
*/
protected $dateFormatter;
/**
* Constructs a \Drupal\aggregator\Controller\AggregatorController object.
*
* @param \Drupal\Core\Datetime\Date $date_formatter
* The date formatter service.
*/
public function __construct(DateFormatter $date_formatter) {
$this->dateFormatter = $date_formatter;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('date')
);
}
/**
* Presents the aggregator feed creation form.
*
......@@ -114,11 +142,11 @@ public function adminOverview() {
foreach ($feeds as $feed) {
$row = array();
$row[] = l($feed->label(), "aggregator/sources/" . $feed->id());
$row[] = format_plural($entity_manager->getStorage('aggregator_item')->getItemCount($feed), '1 item', '@count items');
$row[] = $this->dateFormatter->formatInterval($entity_manager->getStorage('aggregator_item')->getItemCount($feed), '1 item', '@count items');
$last_checked = $feed->getLastCheckedTime();
$refresh_rate = $feed->getRefreshRate();
$row[] = ($last_checked ? $this->t('@time ago', array('@time' => format_interval(REQUEST_TIME - $last_checked))) : $this->t('never'));
$row[] = ($last_checked && $refresh_rate ? $this->t('%time left', array('%time' => format_interval($last_checked + $refresh_rate - REQUEST_TIME))) : $this->t('never'));
$row[] = ($last_checked ? $this->t('@time ago', array('@time' => $this->dateFormatter->formatInterval(REQUEST_TIME - $last_checked))) : $this->t('never'));
$row[] = ($last_checked && $refresh_rate ? $this->t('%time left', array('%time' => $this->dateFormatter->formatInterval($last_checked + $refresh_rate - REQUEST_TIME))) : $this->t('never'));
$links['edit'] = array(
'title' => $this->t('Edit'),
'route_name' => 'aggregator.feed_configure',
......
......@@ -162,7 +162,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
));
$intervals = array(900, 1800, 3600, 7200, 10800, 21600, 32400, 43200, 64800, 86400, 172800, 259200, 604800, 1209600, 2419200);
$period = array_map('format_interval', array_combine($intervals, $intervals));
$period = array_map(array(\Drupal::service('date'), 'formatInterval'), array_combine($intervals, $intervals));
$period[AGGREGATOR_CLEAR_NEVER] = t('Never');
$fields['refresh'] = FieldDefinition::create('list_integer')
......
......@@ -68,7 +68,7 @@ public function getFormId() {
*/
public function buildForm(array $form, array &$form_state) {
$intervals = array(900, 1800, 3600, 7200, 10800, 21600, 32400, 43200, 64800, 86400, 172800, 259200, 604800, 1209600, 2419200);
$period = array_map('format_interval', array_combine($intervals, $intervals));
$period = array_map(array(\Drupal::service('date'), 'formatInterval'), array_combine($intervals, $intervals));
$form['upload'] = array(
'#type' => 'file',
......
......@@ -13,6 +13,7 @@
use Drupal\aggregator\FeedInterface;
use Drupal\Core\Database\Database;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Datetime\Date as DateFormatter;
use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -51,6 +52,13 @@ class DefaultProcessor extends AggregatorPluginSettingsBase implements Processor
*/
protected $itemStorage;
/**
* The date formatter service.
*
* @var \Drupal\Core\Datetime\Date
*/
protected $dateFormatter;
/**
* Constructs a DefaultProcessor object.
*
......@@ -66,11 +74,14 @@ class DefaultProcessor extends AggregatorPluginSettingsBase implements Processor
* The entity query object for feed items.
* @param \Drupal\aggregator\ItemStorageInterface $item_storage
* The entity storage for feed items.
* @param \Drupal\Core\Datetime\Date $date_formatter
* The date formatter service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config, QueryInterface $item_query, ItemStorageInterface $item_storage) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config, QueryInterface $item_query, ItemStorageInterface $item_storage, DateFormatter $date_formatter) {
$this->configFactory = $config;
$this->itemStorage = $item_storage;
$this->itemQuery = $item_query;
$this->dateFormatter = $date_formatter;
// @todo Refactor aggregator plugins to ConfigEntity so merging
// the configuration here is not needed.
parent::__construct($configuration + $this->getConfiguration(), $plugin_id, $plugin_definition);
......@@ -86,7 +97,8 @@ public static function create(ContainerInterface $container, array $configuratio
$plugin_definition,
$container->get('config.factory'),
$container->get('entity.query')->get('aggregator_item'),
$container->get('entity.manager')->getStorage('aggregator_item')
$container->get('entity.manager')->getStorage('aggregator_item'),
$container->get('date')
);
}
......@@ -98,10 +110,10 @@ public function buildConfigurationForm(array $form, array &$form_state) {
$info = $this->getPluginDefinition();
$counts = array(3, 5, 10, 15, 20, 25);
$items = array_map(function ($count) {
return format_plural($count, '1 item', '@count items');
return $this->dateFormatter->formatInterval($count, '1 item', '@count items');
}, array_combine($counts, $counts));
$intervals = array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800);
$period = array_map('format_interval', array_combine($intervals, $intervals));
$period = array_map(array($this->dateFormatter, 'formatInterval'), array_combine($intervals, $intervals));
$period[AGGREGATOR_CLEAR_NEVER] = t('Never');
$form['processors'][$info['id']] = array();
......
......@@ -65,7 +65,6 @@ public function label() {
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->setConfiguration($configuration);
}
......@@ -227,7 +226,7 @@ public function buildConfigurationForm(array $form, array &$form_state) {
// Identical options to the ones for page caching.
// @see \Drupal\system\Form\PerformanceForm::buildForm()
$period = array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400);
$period = array_map('format_interval', array_combine($period, $period));
$period = array_map(array(\Drupal::service('date'), 'formatInterval'), array_combine($period, $period));
$period[0] = '<' . t('no caching') . '>';
$period[\Drupal\Core\Cache\Cache::PERMANENT] = t('Forever');
$form['cache'] = array(
......
......@@ -61,7 +61,7 @@ public function testBlockInterface() {
$definition = $display_block->getPluginDefinition();
$period = array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400);
$period = array_map('format_interval', array_combine($period, $period));
$period = array_map(array(\Drupal::service('date'), 'formatInterval'), array_combine($period, $period));
$period[0] = '<' . t('no caching') . '>';
$period[\Drupal\Core\Cache\Cache::PERMANENT] = t('Forever');
$contexts = \Drupal::service("cache_contexts")->getLabels();
......
......@@ -10,7 +10,7 @@
use Drupal\comment\CommentInterface;
use Drupal\comment\CommentStorageInterface;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Datetime\Date;
use Drupal\Core\Datetime\Date as DateFormatter;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormBase;
......@@ -36,11 +36,11 @@ class CommentAdminOverview extends FormBase {
protected $commentStorage;
/**
* Date service object.
* The date formatter service.
*
* @var \Drupal\Core\Datetime\Date
*/
protected $date;
protected $dateFormatter;
/**
* The module handler.
......@@ -56,15 +56,15 @@ class CommentAdminOverview extends FormBase {
* The entity manager service.
* @param \Drupal\comment\CommentStorageInterface $comment_storage
* The comment storage.
* @param \Drupal\Core\Datetime\Date $date
* The date service.
* @param \Drupal\Core\Datetime\Date $date_formatter
* The date formatter service.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
public function __construct(EntityManagerInterface $entity_manager, CommentStorageInterface $comment_storage, Date $date, ModuleHandlerInterface $module_handler) {
public function __construct(EntityManagerInterface $entity_manager, CommentStorageInterface $comment_storage, DateFormatter $date_formatter, ModuleHandlerInterface $module_handler) {
$this->entityManager = $entity_manager;
$this->commentStorage = $comment_storage;
$this->date = $date;
$this->dateFormatter = $date_formatter;
$this->moduleHandler = $module_handler;
}
......@@ -209,7 +209,7 @@ public function buildForm(array $form, array &$form_state, $type = 'new') {
'#access' => $commented_entity->access('view'),
) + $commented_entity->urlInfo()->toRenderArray(),
),
'changed' => $this->date->format($comment->getChangedTime(), 'short'),
'changed' => $this->dateFormatter->format($comment->getChangedTime(), 'short'),
);
$comment_uri_options = $comment->urlInfo()->getOptions();
$links = array();
......
......@@ -59,8 +59,8 @@ function testCommentTokenReplacement() {
$tests['[comment:body]'] = $comment->comment_body->processed;
$tests['[comment:url]'] = url('comment/' . $comment->id(), $url_options + array('fragment' => 'comment-' . $comment->id()));
$tests['[comment:edit-url]'] = url('comment/' . $comment->id() . '/edit', $url_options);
$tests['[comment:created:since]'] = format_interval(REQUEST_TIME - $comment->getCreatedTime(), 2, $language_interface->id);
$tests['[comment:changed:since]'] = format_interval(REQUEST_TIME - $comment->getChangedTime(), 2, $language_interface->id);
$tests['[comment:created:since]'] = \Drupal::service('date')->formatInterval(REQUEST_TIME - $comment->getCreatedTime(), 2, $language_interface->id);
$tests['[comment:changed:since]'] = \Drupal::service('date')->formatInterval(REQUEST_TIME - $comment->getChangedTime(), 2, $language_interface->id);
$tests['[comment:parent:cid]'] = $comment->hasParentComment() ? $comment->getParentComment()->id() : NULL;
$tests['[comment:parent:title]'] = String::checkPlain($parent_comment->getSubject());
$tests['[comment:node:nid]'] = $comment->getCommentedEntityId();
......
......@@ -8,6 +8,7 @@
namespace Drupal\contact\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Datetime\Date as DateFormatter;
use Drupal\Core\Flood\FloodInterface;
use Drupal\contact\CategoryInterface;
use Drupal\user\UserInterface;
......@@ -28,14 +29,24 @@ class ContactController extends ControllerBase {
*/
protected $flood;
/**
* The date formatter service.
*
* @var \Drupal\Core\Datetime\Date
*/
protected $dateFormatter;
/**
* Constructs a ContactController object.
*
* @param \Drupal\Core\Flood\FloodInterface $flood
* The flood service.
* @param \Drupal\Core\Datetime\Date $date_formatter
* The date service.
*/
public function __construct(FloodInterface $flood) {
public function __construct(FloodInterface $flood, DateFormatter $date_formatter) {
$this->flood = $flood;
$this->dateFormatter = $date_formatter;
}
/**
......@@ -43,7 +54,8 @@ public function __construct(FloodInterface $flood) {
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('flood')
$container->get('flood'),
$container->get('date')
);
}
......@@ -131,7 +143,7 @@ protected function contactFloodControl() {
if (!$this->flood->isAllowed('contact', $limit, $interval)) {
drupal_set_message($this->t('You cannot send more than %limit messages in @interval. Try again later.', array(
'%limit' => $limit,
'@interval' => format_interval($interval),
'@interval' => $this->dateFormatter->formatInterval($interval),
)), 'error');
throw new AccessDeniedHttpException();
}
......
......@@ -209,7 +209,7 @@ function testPersonalContactFlood() {
// Submit contact form one over limit.
$this->drupalGet('user/' . $this->contact_user->id(). '/contact');
$this->assertRaw(t('You cannot send more than %number messages in @interval. Try again later.', array('%number' => $flood_limit, '@interval' => format_interval(\Drupal::config('contact.settings')->get('flood.interval')))), 'Normal user denied access to flooded contact form.');
$this->assertRaw(t('You cannot send more than %number messages in @interval. Try again later.', array('%number' => $flood_limit, '@interval' => \Drupal::service('date')->formatInterval(\Drupal::config('contact.settings')->get('flood.interval')))), 'Normal user denied access to flooded contact form.');
// Test that the admin user can still access the contact form even though
// the flood limit was reached.
......
......@@ -212,7 +212,7 @@ function testSiteWideContact() {
// Submit contact form one over limit.
$this->drupalGet('contact');
$this->assertResponse(403);
$this->assertRaw(t('You cannot send more than %number messages in @interval. Try again later.', array('%number' => \Drupal::config('contact.settings')->get('flood.limit'), '@interval' => format_interval(600))));
$this->assertRaw(t('You cannot send more than %number messages in @interval. Try again later.', array('%number' => \Drupal::config('contact.settings')->get('flood.limit'), '@interval' => \Drupal::service('date')->formatInterval(600))));
// Test listing controller.
$this->drupalLogin($admin_user);
......
......@@ -7,7 +7,7 @@
namespace Drupal\datetime\Plugin\Field\FieldFormatter;
use Drupal\Core\Datetime\Date;
use Drupal\Core\Datetime\Date as DateFormatter;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
......@@ -39,11 +39,11 @@ public static function defaultSettings() {
}
/**
* The date service.
* The date formatter service.
*
* @var \Drupal\Core\Datetime\Date
*/
protected $dateService;
protected $dateFormatter;
/**
* The date storage.
......@@ -69,15 +69,15 @@ public static function defaultSettings() {
* The view mode.
* @param array $third_party_settings
* Third party settings.
* @param \Drupal\Core\Datetime\Date $date_service
* The date service.
* @param \Drupal\Core\Datetime\Date $date_formatter
* The date formatter service.
* @param \Drupal\Core\Entity\EntityStorageInterface $date_storage
* The date storage.
*/
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, Date $date_service, EntityStorageInterface $date_storage) {
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, DateFormatter $date_formatter, EntityStorageInterface $date_storage) {
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings);
$this->dateService = $date_service;
$this->dateFormatter = $date_formatter;
$this->dateStorage = $date_storage;
}
......@@ -156,7 +156,7 @@ public function viewElements(FieldItemListInterface $items) {
*/
function dateFormat($date) {
$format_type = $this->getSetting('format_type');
return $this->dateService->format($date->getTimestamp(), $format_type);
return $this->dateFormatter->format($date->getTimestamp(), $format_type);
}
/**
......@@ -166,7 +166,7 @@ public function settingsForm(array $form, array &$form_state) {
$time = new DrupalDateTime();
$format_types = $this->dateStorage->loadMultiple();
foreach ($format_types as $type => $type_info) {
$format = $this->dateService->format($time->format('U'), $type);
$format = $this->dateFormatter->format($time->format('U'), $type);
$options[$type] = $type_info->label() . ' (' . $format . ')';
}
......
......@@ -12,7 +12,7 @@
use Drupal\Component\Utility\Xss;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Database\Connection;
use Drupal\Core\Datetime\Date;
use Drupal\Core\Datetime\Date as DateFormatter;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormBuilderInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -37,11 +37,11 @@ class DbLogController extends ControllerBase {
protected $moduleHandler;
/**
* The date service.
* The date formatter service.
*
* @var \Drupal\Core\Datetime\Date
*/
protected $date;
protected $dateFormatter;
/**
* The form builder service.
......@@ -69,15 +69,15 @@ public static function create(ContainerInterface $container) {
* A database connection.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* A module handler.
* @param \Drupal\Core\Datetime\Date $date
* The date service.
* @param \Drupal\Core\Datetime\Date $date_formatter
* The date formatter service.
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
* The form builder service.
*/
public function __construct(Connection $database, ModuleHandlerInterface $module_handler, Date $date, FormBuilderInterface $form_builder) {
public function __construct(Connection $database, ModuleHandlerInterface $module_handler, DateFormatter $date_formatter, FormBuilderInterface $form_builder) {
$this->database = $database;
$this->moduleHandler = $module_handler;
$this->date = $date;
$this->dateFormatter = $date_formatter;
$this->formBuilder = $form_builder;
}
......@@ -184,7 +184,7 @@ public function overview() {
// Cells.
array('class' => array('icon')),
$this->t($dblog->type),
$this->date->format($dblog->timestamp, 'short'),
$this->dateFormatter->format($dblog->timestamp, 'short'),
$message,
array('data' => $username),
Xss::filter($dblog->link),
......@@ -237,7 +237,7 @@ public function eventDetails($event_id) {
),
array(
array('data' => $this->t('Date'), 'header' => TRUE),
$this->date->format($dblog->timestamp, 'long'),
$this->dateFormatter->format($dblog->timestamp, 'long'),
),
array(
array('data' => $this->t('User'), 'header' => TRUE),
......
......@@ -737,7 +737,7 @@ function template_preprocess_forum_submitted(&$variables) {
$username = array('#theme' => 'username', '#account' => user_load($variables['topic']->uid));
$variables['author'] = drupal_render($username);
}
$variables['time'] = isset($variables['topic']->created) ? format_interval(REQUEST_TIME - $variables['topic']->created) : '';
$variables['time'] = isset($variables['topic']->created) ? \Drupal::service('date')->formatInterval(REQUEST_TIME - $variables['topic']->created) : '';
}
/**
......
......@@ -156,6 +156,6 @@ function template_preprocess_locale_translation_update_info(&$variables) {
function template_preprocess_locale_translation_last_check(&$variables) {
$last = $variables['last'];
$variables['last_checked'] = ($last != NULL);
$variables['time'] = format_interval(REQUEST_TIME - $last);
$variables['time'] = \Drupal::service('date')->formatInterval(REQUEST_TIME - $last);
$variables['link'] = l(t('Check manually'), 'admin/reports/translations/check', array('query' => drupal_get_destination()));
}
......@@ -10,7 +10,7 @@
use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Datetime\Date;
use Drupal\Core\Datetime\Date as DateFormatter;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\node\NodeTypeInterface;
use Drupal\node\NodeInterface;
......@@ -22,20 +22,20 @@
class NodeController extends ControllerBase implements ContainerInjectionInterface {
/**
* The date service.
* The date formatter service.
*
* @var \Drupal\Core\Datetime\Date
*/
protected $date;
protected $dateFormatter;
/**
* Constructs a NodeController object.
*
* @param \Drupal\Core\Datetime\Date $date
* The date service.
* @param \Drupal\Core\Datetime\Date $date_formatter
* The date formatter service.
*/
public function __construct(Date $date) {
$this->date = $date;
public function __construct(DateFormatter $date_formatter) {
$this->dateFormatter = $date_formatter;
}
/**
......@@ -173,7 +173,7 @@ public function revisionOverview(NodeInterface $node) {
'#theme' => 'username',
'#account' => $revision_author,
);
$row[] = array('data' => $this->t('!date by !username', array('!date' => $this->l($this->date->format($revision->revision_timestamp->value, 'short'), 'node.view', array('node' => $node->id())), '!username' => drupal_render($username)))
$row[] = array('data' => $this->t('!date by !username', array('!date' => $this->l($this->dateFormatter->format($revision->revision_timestamp->value, 'short'), 'node.view', array('node' => $node->id())), '!username' => drupal_render($username)))
. (($revision->revision_log->value != '') ? '<p class="revision-log">' . Xss::filter($revision->revision_log->value) . '</p>' : ''),
'class' => array('revision-current'));
$row[] = array('data' => String::placeholder($this->t('current revision')), 'class' => array('revision-current'));
......@@ -183,7 +183,7 @@ public function revisionOverview(NodeInterface $node) {
'#theme' => 'username',
'#account' => $revision_author,
);
$row[] = $this->t('!date by !username', array('!date' => $this->l($this->date->format($revision->revision_timestamp->value, 'short'), 'node.revision_show', array('node' => $node->id(), 'node_revision' => $vid)), '!username' => drupal_render($username)))
$row[] = $this->t('!date by !username', array('!date' => $this->l($this->dateFormatter->format($revision->revision_timestamp->value, 'short'), 'node.revision_show', array('node' => $node->id(), 'node_revision' => $vid)), '!username' => drupal_render($username)))
. (($revision->revision_log->value != '') ? '<p class="revision-log">' . Xss::filter($revision->revision_log->value) . '</p>' : '');
if ($revert_permission) {
......
......@@ -8,7 +8,7 @@
namespace Drupal\node;
use Drupal\Component\Utility\String;
use Drupal\Core\Datetime\Date;
use Drupal\Core\Datetime\Date as DateFormatter;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Entity\EntityStorageInterface;
......@@ -24,11 +24,11 @@
class NodeListBuilder extends EntityListBuilder {
/**
* The date service.
* The date formatter service.
*
* @var \Drupal\Core\Datetime\Date
*/
protected $dateService;
protected $dateFormatter;
/**
* Constructs a new NodeListBuilder object.
......@@ -37,13 +37,13 @@ class NodeListBuilder extends EntityListBuilder {
* The entity type definition.
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The entity storage class.
* @param \Drupal\Core\Datetime\Date $date_service
* The date service.
* @param \Drupal\Core\Datetime\Date $date_formatter
* The date formatter service.
*/
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, Date $date_service) {
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, DateFormatter $date_formatter) {
parent::__construct($entity_type, $storage);
$this->dateService = $date_service;
$this->dateFormatter = $date_formatter;
}
/**
......@@ -112,7 +112,7 @@ public function buildRow(EntityInterface $entity) {
'#account' => $entity->getOwner(),
);
$row['status'] = $entity->isPublished() ? $this->t('published') : $this->t('not published');
$row['changed'] = $this->dateService->format($entity->getChangedTime(), 'short');
$row['changed'] = $this->dateFormatter->format($entity->getChangedTime(), 'short');
$language_manager = \Drupal::languageManager();
if ($language_manager->isMultilingual()) {
$row['language_name'] = $language_manager->getLanguageName($langcode);
......
......@@ -8,7 +8,7 @@
namespace Drupal\system;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Datetime\Date;
use Drupal\Core\Datetime\Date as DateFormatter;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
......@@ -22,11 +22,11 @@
class DateFormatListBuilder extends ConfigEntityListBuilder {
/**
* The date service.
* The date formatter service.
*
* @var \Drupal\Core\Datetime\Date
*/
protected $dateService;
protected $dateFormatter;
/**
* Constructs a new DateFormatListBuilder object.
......@@ -35,13 +35,13 @@ class DateFormatListBuilder extends ConfigEntityListBuilder {
* The entity type definition.
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The entity storage class.
* @param \Drupal\Core\Datetime\Date $date_service
* The date service.
* @param \Drupal\Core\Datetime\Date $date_formatter
* The date formatter service.
*/
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, Date $date_service) {
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, DateFormatter $date_formatter) {
parent::__construct($entity_type, $storage);
$this->dateService = $date_service;
$this->dateFormatter = $date_formatter;
}
/**
......@@ -76,7 +76,7 @@ public function buildRow(EntityInterface $entity) {
$row['id'] = $entity->id();
}
$row['label'] = $this->getLabel($entity);
$row['pattern'] = $this->dateService->format(REQUEST_TIME, $entity->id());
$row['pattern'] = $this->dateFormatter->format(REQUEST_TIME, $entity->id());
return $row + parent::buildRow($entity);
}
......
......@@ -9,6 +9,7 @@
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\CronInterface;
use Drupal\Core\Datetime\Date as DateFormatter;
use Drupal\Core\State\StateInterface;
use Drupal\Core\Form\ConfigFormBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -33,6 +34,13 @@ class CronForm extends ConfigFormBase {
*/
protected $cron;
/**
* The date formatter service.
*
* @var \Drupal\Core\Datetime\Date
*/
protected $dateFormatter;
/**
* Constructs a CronForm object.
*
......@@ -42,11 +50,14 @@ class CronForm extends ConfigFormBase {
* The state key value store.
* @param \Drupal\Core\CronInterface $cron
* The cron service.
* @param \Drupal\Core\Datetime\Date $date_formatter
* The date formatter service.
*/
public function __construct(ConfigFactoryInterface $config_factory, StateInterface $state, CronInterface $cron) {
public function __construct(ConfigFactoryInterface $config_factory, StateInterface $state, CronInterface $cron, DateFormatter $date_formatter) {
parent::__construct($config_factory);
$this->state = $state;
$this->cron = $cron;
$this->dateFormatter = $date_formatter;
}
/**
......@@ -56,7 +67,8 @@ public static function create(ContainerInterface $container) {