public function EntityTreeBuilder::createTreeNode in Entity Reference Tree Widget 8
Same name and namespace in other branches
- 2.x src/Tree/EntityTreeBuilder.php \Drupal\entity_reference_tree\Tree\EntityTreeBuilder::createTreeNode()
Create a tree node.
Parameters
$entity: The entity for the tree node.
array $selected: A anrray for all selected nodes.
Return value
array The tree node for the entity.
Overrides TreeBuilderInterface::createTreeNode
File
- src/
Tree/ EntityTreeBuilder.php, line 103
Class
- EntityTreeBuilder
- Provides a class for building a tree from general entity.
Namespace
Drupal\entity_reference_tree\TreeCode
public function createTreeNode($entity, array $selected = []) {
$node = [
// Required.
'id' => $entity->id,
// Required.
'parent' => $entity->parent,
// Node text.
'text' => $entity->text,
'state' => [
'selected' => FALSE,
],
];
if (in_array($entity->id, $selected)) {
// Initially selected node.
$node['state']['selected'] = TRUE;
}
return $node;
}