diff --git a/core/modules/tracker/src/Tests/TrackerTest.php b/core/modules/tracker/src/Tests/TrackerTest.php index 80f6fa5..4b3160c 100644 --- a/core/modules/tracker/src/Tests/TrackerTest.php +++ b/core/modules/tracker/src/Tests/TrackerTest.php @@ -8,6 +8,7 @@ namespace Drupal\tracker\Tests; use Drupal\comment\CommentInterface; +use Drupal\field\Entity\FieldStorageConfig; use Drupal\simpletest\WebTestBase; /** @@ -22,7 +23,7 @@ class TrackerTest extends WebTestBase { * * @var array */ - public static $modules = array('comment', 'tracker', 'history'); + public static $modules = array('comment', 'tracker', 'history', 'node_test'); /** * The main user for testing. @@ -73,6 +74,21 @@ function testTrackerAll() { $published->delete(); $this->drupalGet('activity'); $this->assertNoText($published->label(), 'Deleted node does not show up in the tracker listing.'); + + // Test proper display of time on activity page when comments are disabled. + // Disable comments. + FieldStorageConfig::loadByName('node', 'comment')->delete(); + $node = $this->drupalCreateNode([ + // This title is required to trigger the custom changed time set in the + // node_test module. This is needed in order to ensure a sufficiently + // large 'time ago' interval that isn't numbered in seconds. + 'title' => 'testing_node_presave', + 'status' => 1, + ]); + + $this->drupalGet('activity'); + $this->assertText($node->label(), 'Published node shows up in the tracker listing.'); + $this->assertText(\Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $node->getChangedTime()), 'The changed time was displayed on the tracker listing.'); } /** diff --git a/core/modules/tracker/tracker.pages.inc b/core/modules/tracker/tracker.pages.inc index 04d70fa..ebcb14d 100644 --- a/core/modules/tracker/tracker.pages.inc +++ b/core/modules/tracker/tracker.pages.inc @@ -61,12 +61,15 @@ function tracker_page($account = NULL) { else { $nodes[$nid]->comment_count += $statistics->comment_count; } - - $nodes[$nid]->last_activity = $tracker_data[$nid]->changed; } // Display the data. foreach ($nodes as $node) { + // Set last activity time from tracker data (this isn't only the node + // changed time, it can include comment activity, so getChangedTime() is + // not used. + $node->last_activity = $tracker_data[$node->id()]->changed; + // Determine the number of comments. $comments = 0; if ($node->comment_count) { @@ -112,7 +115,7 @@ function tracker_page($account = NULL) { ), 'last updated' => array( 'data' => t('!time ago', array( - '!time' => \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $node->getChangedTime()), + '!time' => \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $node->last_activity), )), ), );