public function ChildEntityWarningBuilder::buildChildEntityWarnings in Entity Reference Hierarchy 8.2
Same name and namespace in other branches
- 3.x src/Information/ChildEntityWarningBuilder.php \Drupal\entity_hierarchy\Information\ChildEntityWarningBuilder::buildChildEntityWarnings()
Gets warning about child entities before deleting a parent.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $parent: Parent to be deleted.
Return value
\Drupal\entity_hierarchy\Information\ChildEntityWarning[] Array of warning value objects.
File
- src/
Information/ ChildEntityWarningBuilder.php, line 86
Class
- ChildEntityWarningBuilder
- Defines a class for building a list of child entity warnings.
Namespace
Drupal\entity_hierarchy\InformationCode
public function buildChildEntityWarnings(ContentEntityInterface $parent) {
$return = [];
if ($fields = $this->parentCandidate
->getCandidateFields($parent)) {
$cache = new CacheableMetadata();
foreach ($fields as $field_name) {
/** @var \PNX\NestedSet\NestedSetInterface $storage */
$storage = $this->nestedSetStorageFactory
->get($field_name, $parent
->getEntityTypeId());
$nodeKey = $this->nodeKeyFactory
->fromEntity($parent);
$children = $storage
->findChildren($nodeKey);
if ($parent_node = $storage
->findParent($nodeKey)) {
$children[] = $parent_node;
}
$entities = $this->treeNodeMapper
->loadAndAccessCheckEntitysForTreeNodes($parent
->getEntityTypeId(), $children, $cache);
$return[] = new ChildEntityWarning($entities, $cache, $parent_node);
}
}
return $return;
}