Version 1
[yaffs-website] / web / core / modules / comment / src / Plugin / views / field / LastTimestamp.php
diff --git a/web/core/modules/comment/src/Plugin/views/field/LastTimestamp.php b/web/core/modules/comment/src/Plugin/views/field/LastTimestamp.php
new file mode 100644 (file)
index 0000000..bbae18d
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+
+namespace Drupal\comment\Plugin\views\field;
+
+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
+ *
+ * @ViewsField("comment_last_timestamp")
+ */
+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;
+    }
+  }
+
+}