public function ChildOfMicrositeLookup::findMicrositesForNodeAndField in Entity Reference Hierarchy 3.x
Same name and namespace in other branches
- 8.2 modules/entity_hierarchy_microsite/src/ChildOfMicrositeLookup.php \Drupal\entity_hierarchy_microsite\ChildOfMicrositeLookup::findMicrositesForNodeAndField()
Gets microsites the node belongs to.
Parameters
\Drupal\node\NodeInterface $node: Node.
string $field_name: Field name.
Return value
\Drupal\entity_hierarchy_microsite\Entity\MicrositeInterface[] Microsites.
Overrides ChildOfMicrositeLookupInterface::findMicrositesForNodeAndField
File
- modules/
entity_hierarchy_microsite/ src/ ChildOfMicrositeLookup.php, line 67
Class
- ChildOfMicrositeLookup
- Defines a class for looking up a microsite given a node.
Namespace
Drupal\entity_hierarchy_micrositeCode
public function findMicrositesForNodeAndField(NodeInterface $node, $field_name) {
$ids = [];
if ($node
->hasField($field_name) && !$node
->get($field_name)
->isEmpty()) {
$key = $this->nodeKeyFactory
->fromEntity($node);
/** @var \PNX\NestedSet\NestedSetInterface $nestedSetStorage */
$nestedSetStorage = $this->nestedSetStorageFactory
->get($field_name, 'node');
$ids = array_map(function (Node $treeNode) {
return $treeNode
->getId();
}, $nestedSetStorage
->findAncestors($key));
}
$ids[] = $node
->id();
$entityStorage = $this->entityTypeManager
->getStorage('entity_hierarchy_microsite');
return $entityStorage
->loadMultiple($entityStorage
->getQuery()
->sort('id')
->condition('home', $ids, 'IN')
->execute());
}