HierarchyIsChildOfEntity.php in Entity Reference Hierarchy 3.x
File
src/Plugin/views/argument/HierarchyIsChildOfEntity.php
View source
<?php
namespace Drupal\entity_hierarchy\Plugin\views\argument;
class HierarchyIsChildOfEntity extends EntityHierarchyArgumentPluginBase {
public function query($group_by = FALSE) {
$this
->ensureMyTable();
$filtered = FALSE;
if ($entity = $this
->loadEntity()) {
$stub = $this->nodeKeyFactory
->fromEntity($entity);
if ($node = $this
->getTreeStorage()
->getNode($stub)) {
$filtered = TRUE;
$lower_token = ':lower_' . $this->tableAlias;
$upper_token = ':upper_' . $this->tableAlias;
$expression = "{$this->tableAlias}.{$this->realField} BETWEEN {$lower_token} and {$upper_token} AND {$this->tableAlias}.{$this->realField} <> {$lower_token}";
$arguments = [
$lower_token => $node
->getLeft(),
$upper_token => $node
->getRight(),
];
if ($depth = $this->options['depth']) {
$depth_token = ':depth_' . $this->tableAlias;
$expression .= " AND {$this->tableAlias}.depth <= {$depth_token}";
$arguments[$depth_token] = $node
->getDepth() + $depth;
}
$this->query
->addWhereExpression(0, $expression, $arguments);
}
}
if (!$filtered) {
$this->query
->addWhereExpression(0, '1 <> 1');
}
}
}