LastTimestamp.php

Same filename and directory in other branches
  1. 9 core/modules/comment/src/Plugin/views/field/LastTimestamp.php
  2. 8.9.x core/modules/comment/src/Plugin/views/field/LastTimestamp.php
  3. 10 core/modules/comment/src/Plugin/views/field/LastTimestamp.php

Namespace

Drupal\comment\Plugin\views\field

File

core/modules/comment/src/Plugin/views/field/LastTimestamp.php

View source
<?php

namespace Drupal\comment\Plugin\views\field;

use Drupal\views\Attribute\ViewsField;
use Drupal\views\Plugin\views\field\Date;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\ResultRow;
use Drupal\views\ViewExecutable;

/**
 * Field handler to display the timestamp of a comment with the count of comments.
 *
 * @ingroup views_field_handlers
 */
class LastTimestamp extends Date {
    
    /**
     * {@inheritdoc}
     */
    public function init(ViewExecutable $view, DisplayPluginBase $display, ?array &$options = NULL) {
        parent::init($view, $display, $options);
        $this->additional_fields['comment_count'] = 'comment_count';
    }
    
    /**
     * {@inheritdoc}
     */
    public function render(ResultRow $values) {
        $comment_count = $this->getValue($values, 'comment_count');
        if (empty($this->options['empty_zero']) || $comment_count) {
            return parent::render($values);
        }
        else {
            return NULL;
        }
    }

}

Classes

Title Deprecated Summary
LastTimestamp Field handler to display the timestamp of a comment with the count of comments.

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