Neos\Neos\Ui\Domain\Service\NodeTreeBuilder::build PHP Метод

build() публичный Метод

Build a json serializable tree structure containing node information
public build ( $includeRoot = false, $root = null, $depth = null ) : array
Результат array
    public function build($includeRoot = false, $root = null, $depth = null)
    {
        $root = $root === null ? $this->getRoot() : $root;
        $depth = $depth === null ? $this->depth : $depth;
        $result = [];
        /** @var NodeInterface $childNode */
        foreach ($root->getChildNodes($this->nodeTypeFilter) as $childNode) {
            $hasChildNodes = $childNode->hasChildNodes($this->nodeTypeFilter);
            $shouldLoadChildNodes = $hasChildNodes && ($depth > 1 || $this->isInRootLine($this->active, $childNode));
            $result[$childNode->getName()] = ['label' => $childNode->getNodeType()->isOfType('TYPO3.Neos:Document') ? $childNode->getProperty('title') : $childNode->getLabel(), 'contextPath' => $childNode->getContextPath(), 'nodeType' => $childNode->getNodeType()->getName(), 'hasChildren' => $hasChildNodes, 'isActive' => $this->active && $childNode->getPath() === $this->active->getPath(), 'isFocused' => $this->active && $childNode->getPath() === $this->active->getPath(), 'isCollapsed' => !$shouldLoadChildNodes, 'isCollapsable' => $hasChildNodes];
            if ($shouldLoadChildNodes) {
                $result[$childNode->getName()]['children'] = $this->build(false, $childNode, $depth - 1);
            }
            if ($childNode->getNodeType()->isOfType('TYPO3.Neos:Document')) {
                $result[$childNode->getName()]['href'] = $this->linkingService->createNodeUri($this->controllerContext, $childNode, null, null, true, [], '', false, [], false);
            }
        }
        if ($includeRoot) {
            return [$root->getName() => ['label' => $root->getNodeType()->isOfType('TYPO3.Neos:Document') ? $root->getProperty('title') : $root->getLabel(), 'icon' => 'globe', 'contextPath' => $root->getContextPath(), 'nodeType' => $root->getNodeType()->getName(), 'hasChildren' => count($result), 'isCollapsed' => false, 'isActive' => $this->active && $root->getPath() === $this->active->getPath(), 'isFocused' => $this->active && $root->getPath() === $this->active->getPath(), 'children' => $result]];
        }
        return $result;
    }

Usage Example

Пример #1
0
 /**
  * Load the nodetree
  *
  * @param NodeTreeBuilder $nodeTreeArguments
  * @param boolean $includeRoot
  * @return void
  */
 public function loadTreeAction(NodeTreeBuilder $nodeTreeArguments, $includeRoot = false)
 {
     $nodeTreeArguments->setControllerContext($this->controllerContext);
     $this->view->assign('value', $nodeTreeArguments->build($includeRoot));
 }