You are here

function _tracker_calculate_changed in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/tracker/tracker.module \_tracker_calculate_changed()
  2. 7 modules/tracker/tracker.module \_tracker_calculate_changed()

Picks the most recent timestamp between node changed and the last comment.

@todo Check if we should introduce 'language context' here, because the callers may need different timestamps depending on the users' language?

Parameters

\Drupal\node\NodeInterface $node: The node entity.

Return value

int The node changed timestamp, or most recent comment timestamp, whichever is the greatest.

2 calls to _tracker_calculate_changed()
tracker_cron in core/modules/tracker/tracker.module
Implements hook_cron().
_tracker_remove in core/modules/tracker/tracker.module
Cleans up indexed data when nodes or comments are removed.

File

core/modules/tracker/tracker.module, line 266
Tracks recent content posted by a user or users.

Code

function _tracker_calculate_changed($node) {
  $changed = $node
    ->getChangedTime();
  $latest_comment = \Drupal::service('comment.statistics')
    ->read([
    $node,
  ], 'node', FALSE);
  if ($latest_comment && $latest_comment->last_comment_timestamp > $changed) {
    $changed = $latest_comment->last_comment_timestamp;
  }
  return $changed;
}