You are here

public function HistoryUserTimestamp::render in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/history/src/Plugin/views/field/HistoryUserTimestamp.php \Drupal\history\Plugin\views\field\HistoryUserTimestamp::render()

Renders the field.

Parameters

\Drupal\views\ResultRow $values: The values retrieved from a single row of a view's query result.

Return value

string|\Drupal\Component\Render\MarkupInterface The rendered output. If the output is safe it will be wrapped in an object that implements MarkupInterface. If it is empty or unsafe it will be a string.

Overrides Node::render

File

core/modules/history/src/Plugin/views/field/HistoryUserTimestamp.php, line 80
Contains \Drupal\history\Plugin\views\field\HistoryUserTimestamp.

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 = array(
      '#theme' => 'mark',
      '#status' => $mark,
    );
    return $this
      ->renderLink(drupal_render($build), $values);
  }
}