Version 1
[yaffs-website] / web / core / modules / comment / src / Plugin / views / field / Depth.php
diff --git a/web/core/modules/comment/src/Plugin/views/field/Depth.php b/web/core/modules/comment/src/Plugin/views/field/Depth.php
new file mode 100644 (file)
index 0000000..04b43c7
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+
+namespace Drupal\comment\Plugin\views\field;
+
+use Drupal\views\Plugin\views\field\EntityField;
+use Drupal\views\ResultRow;
+
+/**
+ * Field handler to display the depth of a comment.
+ *
+ * @ingroup views_field_handlers
+ *
+ * @ViewsField("comment_depth")
+ */
+class Depth extends EntityField {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getItems(ResultRow $values) {
+    $items = parent::getItems($values);
+
+    foreach ($items as &$item) {
+      // Work out the depth of this comment.
+      $comment_thread = $item['rendered']['#markup'];
+      $item['rendered']['#markup'] = count(explode('.', $comment_thread)) - 1;
+    }
+    return $items;
+  }
+
+}