You are here

Depth.php in Zircon Profile 8

Same filename and directory in other branches
  1. 8.0 core/modules/comment/src/Plugin/views/field/Depth.php

File

core/modules/comment/src/Plugin/views/field/Depth.php
View source
<?php

/**
 * @file
 * Contains \Drupal\comment\Plugin\views\field\Depth.
 */
namespace Drupal\comment\Plugin\views\field;

use Drupal\views\Plugin\views\field\Field;
use Drupal\views\ResultRow;

/**
 * Field handler to display the depth of a comment.
 *
 * @ingroup views_field_handlers
 *
 * @ViewsField("comment_depth")
 */
class Depth extends Field {

  /**
   * {@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;
  }

}

Classes

Namesort descending Description
Depth Field handler to display the depth of a comment.