Depth.php

Same filename and directory in other branches
  1. 8.9.x core/modules/comment/src/Plugin/views/field/Depth.php
  2. 10 core/modules/comment/src/Plugin/views/field/Depth.php
  3. 11.x core/modules/comment/src/Plugin/views/field/Depth.php

Namespace

Drupal\comment\Plugin\views\field

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;

/**
 * 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']['#context']['value'];
            $item['rendered']['#context']['value'] = count(explode('.', $comment_thread)) - 1;
        }
        return $items;
    }

}

Classes

Title Deprecated Summary
Depth Field handler to display the depth of a comment.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.