function HistoryUserTimestamp::render

Same name in other branches
  1. 9 core/modules/history/src/Plugin/views/field/HistoryUserTimestamp.php \Drupal\history\Plugin\views\field\HistoryUserTimestamp::render()
  2. 10 core/modules/history/src/Plugin/views/field/HistoryUserTimestamp.php \Drupal\history\Plugin\views\field\HistoryUserTimestamp::render()
  3. 11.x core/modules/history/src/Plugin/views/field/HistoryUserTimestamp.php \Drupal\history\Plugin\views\field\HistoryUserTimestamp::render()

Overrides Node::render

File

core/modules/history/src/Plugin/views/field/HistoryUserTimestamp.php, line 84

Class

HistoryUserTimestamp
Field handler to display the marker for new content.

Namespace

Drupal\history\Plugin\views\field

Code

public function render(ResultRow $values) {
    // Let's default to 'read' state.
    // This code shadows node_mark, but it reads from the db directly and
    // we already have that info.
    $mark = MARK_READ;
    if (\Drupal::currentUser()->isAuthenticated()) {
        $last_read = $this->getValue($values);
        $changed = $this->getValue($values, 'changed');
        $last_comment = \Drupal::moduleHandler()->moduleExists('comment') && !empty($this->options['comments']) ? $this->getValue($values, 'last_comment') : 0;
        if (!$last_read && $changed > HISTORY_READ_LIMIT) {
            $mark = MARK_NEW;
        }
        elseif ($changed > $last_read && $changed > HISTORY_READ_LIMIT) {
            $mark = MARK_UPDATED;
        }
        elseif ($last_comment > $last_read && $last_comment > HISTORY_READ_LIMIT) {
            $mark = MARK_UPDATED;
        }
        $build = [
            '#theme' => 'mark',
            '#status' => $mark,
        ];
        return $this->renderLink(\Drupal::service('renderer')->render($build), $values);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.