Version 1
[yaffs-website] / web / core / modules / comment / src / Plugin / views / field / Depth.php
1 <?php
2
3 namespace Drupal\comment\Plugin\views\field;
4
5 use Drupal\views\Plugin\views\field\EntityField;
6 use Drupal\views\ResultRow;
7
8 /**
9  * Field handler to display the depth of a comment.
10  *
11  * @ingroup views_field_handlers
12  *
13  * @ViewsField("comment_depth")
14  */
15 class Depth extends EntityField {
16
17   /**
18    * {@inheritdoc}
19    */
20   public function getItems(ResultRow $values) {
21     $items = parent::getItems($values);
22
23     foreach ($items as &$item) {
24       // Work out the depth of this comment.
25       $comment_thread = $item['rendered']['#markup'];
26       $item['rendered']['#markup'] = count(explode('.', $comment_thread)) - 1;
27     }
28     return $items;
29   }
30
31 }