public function HierarchyTreeSummary::render in Entity Reference Hierarchy 3.x
Renders the field.
Parameters
\Drupal\views\ResultRow $values: The values retrieved from a single row of a view's query result.
Return value
string|\Drupal\Component\Render\MarkupInterface The rendered output. If the output is safe it will be wrapped in an object that implements MarkupInterface. If it is empty or unsafe it will be a string.
Overrides FieldPluginBase::render
File
- src/
Plugin/ views/ field/ HierarchyTreeSummary.php, line 108
Class
- HierarchyTreeSummary
- A handler to provide a field that show hierarchy depth of item.
Namespace
Drupal\entity_hierarchy\Plugin\views\fieldCode
public function render(ResultRow $values) {
if ($this->options['summary_type'] == 'child_counts') {
$storage = $this
->getTreeStorage();
$output = [];
if ($entity = $this
->getEntity($values)) {
$stub = $this->nodeKeyFactory
->fromEntity($entity);
$level = 1;
while ($entities = $storage
->findDescendants($stub, 1, $level)) {
// This is inefficient and one reason why this is only an admin tool.
$entities = $this->treeMapper
->loadEntitiesForTreeNodesWithoutAccessChecks($entity
->getEntityTypeId(), $entities);
$output[] = count($entities);
$level++;
}
}
return implode(' / ', $output);
}
}