src/Contao/View/Contao2BackendView/TreePicker.php
private function pushRootModelToTreeCollection(
        DataProviderInterface $dataProvider,
        CollectionInterface $treeCollection,
        $level
    ) {
        $environment   = $this->getEnvironment();
        $inputProvider = $environment->getInputProvider();
        $baseConfig    = $this->prepareFilterForRootCondition();
        $relationships = $environment->getDataDefinition()->getModelRelationshipDefinition();

        if ($inputProvider->hasParameter('orderProperty') && $inputProvider->hasParameter('sortDirection')) {
            $orderProperty = $inputProvider->getParameter('orderProperty');
            $sortDirection = $inputProvider->getParameter('sortDirection');

            $baseConfig->setSorting([$orderProperty => $sortDirection]);
        }

        // Fetch all root elements.
        $collection = $dataProvider->fetchAll($baseConfig);
        if (!$collection->count()) {
            return;
        }

        $mySubTables = [];
        foreach ($relationships->getChildConditions($collection->get(0)->getProviderName()) as $condition) {
            $mySubTables[] = $condition->getDestinationName();
        }

        foreach ($collection as $model) {
            /** @var ModelInterface $model */
            $treeCollection->push($model);
            $this->treeWalkModel($model, ($level + 1), $mySubTables);
        }
    }
private function pushRootModelToTreeCollection(
        DataProviderInterface $dataProvider,
        CollectionInterface $treeCollection,
        $level
    ) {
        $environment   = $this->getEnvironment();
        $inputProvider = $environment->getInputProvider();
        $baseConfig    = $this->prepareFilterForRootCondition();
        $relationships = $environment->getDataDefinition()->getModelRelationshipDefinition();

        if ($inputProvider->hasParameter('orderProperty') && $inputProvider->hasParameter('sortDirection')) {
            $orderProperty = $inputProvider->getParameter('orderProperty');
            $sortDirection = $inputProvider->getParameter('sortDirection');

            $baseConfig->setSorting([$orderProperty => $sortDirection]);
        }

        // Fetch all root elements.
        $collection = $dataProvider->fetchAll($baseConfig);
        if (!$collection->count()) {
            return;
        }

        $mySubTables = [];
        foreach ($relationships->getChildConditions($collection->get(0)->getProviderName()) as $condition) {
            $mySubTables[] = $condition->getDestinationName();
        }

        foreach ($collection as $model) {
            /** @var ModelInterface $model */
            $treeCollection->push($model);
            $this->treeWalkModel($model, ($level + 1), $mySubTables);
        }
    }
private function pushRootModelToTreeCollection ( DataProviderInterface $ dataProvider , CollectionInterface $ treeCollection , $ level ) { $ environment = $ this -> getEnvironment ( ) ; $ inputProvider = $ environment -> getInputProvider ( ) ; $ baseConfig = $ this -> prepareFilterForRootCondition ( ) ; $ relationships = $ environment -> getDataDefinition ( ) -> getModelRelationshipDefinition ( ) ; if ( $ inputProvider -> hasParameter ( 'orderProperty' ) && $ inputProvider -> hasParameter ( 'sortDirection' ) ) { $ orderProperty = $ inputProvider -> getParameter ( 'orderProperty' ) ; $ sortDirection = $ inputProvider -> getParameter ( 'sortDirection' ) ; $ baseConfig -> setSorting ( [ $ orderProperty => $ sortDirection ] ) ; } // Fetch all root elements. $ collection = $ dataProvider -> fetchAll ( $ baseConfig ) ; if ( ! $ collection -> count ( ) ) { return ; } $ mySubTables = [ ] ; foreach ( $ relationships -> getChildConditions ( $ collection -> get ( 0 ) -> getProviderName ( ) ) as $ condition ) { $ mySubTables [ ] = $ condition -> getDestinationName ( ) ; } foreach ( $ collection as $ model ) { /** @var ModelInterface $model */ $ treeCollection -> push ( $ model ) ; $ this -> treeWalkModel ( $ model , ( $ level + 1 ) , $ mySubTables ) ; } }
Push root model to the tree collection.

@param DataProviderInterface $dataProvider   The data provider.
@param CollectionInterface   $treeCollection The tree collection.
@param int                   $level          The level the items are residing on.

@return void
Push root model to the tree collection .