Depth.php in Drupal 9
File
core/modules/comment/src/Plugin/views/field/Depth.php
View source
<?php
namespace Drupal\comment\Plugin\views\field;
use Drupal\views\Plugin\views\field\EntityField;
use Drupal\views\ResultRow;
class Depth extends EntityField {
public function getItems(ResultRow $values) {
$items = parent::getItems($values);
foreach ($items as &$item) {
$comment_thread = $item['rendered']['#context']['value'];
$item['rendered']['#context']['value'] = count(explode('.', $comment_thread)) - 1;
}
return $items;
}
}
Classes
Name |
Description |
Depth |
Field handler to display the depth of a comment. |