You are here

protected function HierarchyNestedSetRevisionIntegrationTest::getChildren in Entity Reference Hierarchy 3.x

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/HierarchyNestedSetRevisionIntegrationTest.php \Drupal\Tests\entity_hierarchy\Kernel\HierarchyNestedSetRevisionIntegrationTest::getChildren()

Gets children of a given node.

Parameters

\PNX\NestedSet\Node $parent_node: Parent node.

Return value

\PNX\NestedSet\Node[] Children

Overrides HierarchyNestedSetIntegrationTest::getChildren

File

tests/src/Kernel/HierarchyNestedSetRevisionIntegrationTest.php, line 69

Class

HierarchyNestedSetRevisionIntegrationTest
Tests integration with entity_hierarchy and a revisionable entity.

Namespace

Drupal\Tests\entity_hierarchy\Kernel

Code

protected function getChildren(Node $parent_node) {
  $children = parent::getChildren($parent_node);

  // Limit to latest revisions only.
  $entity_storage = $this->container
    ->get('entity_type.manager')
    ->getStorage(static::ENTITY_TYPE);
  $entities = $entity_storage
    ->loadMultiple();
  $revisions = array_map(function (EntityInterface $entity) {
    return $entity
      ->getRevisionId();
  }, $entities);
  $children = array_values(array_filter($children, function (Node $node) use ($revisions) {
    return in_array($node
      ->getRevisionId(), $revisions, TRUE);
  }));
  return $children;
}