LastTimestamp.php 1.02 KB
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Definition of Views\comment\Plugin\views\field\LastTimestamp.
6 7
 */

8
namespace Views\comment\Plugin\views\field;
dawehner's avatar
dawehner committed
9

10
use Drupal\views\Plugin\views\field\Date;
dawehner's avatar
dawehner committed
11
use Drupal\Core\Annotation\Plugin;
12
use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
dawehner's avatar
dawehner committed
13

14 15 16 17
/**
 * Field handler to display the timestamp of a comment with the count of comments.
 *
 * @ingroup views_field_handlers
18
 *
dawehner's avatar
dawehner committed
19
 * @Plugin(
20 21
 *   id = "comment_last_timestamp",
 *   module = "comment"
dawehner's avatar
dawehner committed
22 23 24
 * )
 */
class LastTimestamp extends Date {
25

26 27 28 29 30 31
  /**
   * Constructs a LastTimestamp object.
   */
  public function __construct(array $configuration, $plugin_id, DiscoveryInterface $discovery) {
    parent::__construct($configuration, $plugin_id, $discovery);

32 33 34 35 36 37 38 39 40 41 42 43
    $this->additional_fields['comment_count'] = 'comment_count';
  }

  function render($values) {
    $comment_count = $this->get_value($values, 'comment_count');
    if (empty($this->options['empty_zero']) || $comment_count) {
      return parent::render($values);
    }
    else {
      return NULL;
    }
  }
44

45
}