src/Contao/View/Contao2BackendView/TreeView.php
protected function generateTreeView($collection, $treeClass)
    {
        $content = [];

        // Generate buttons - only if not in select mode!
        if (!$this->isSelectModeActive()) {
            (new ButtonRenderer($this->environment))->renderButtonsForCollection($collection);
        }

        foreach ($collection as $model) {
            /** @var ModelInterface $model */

            $toggleID = $model->getProviderName() . '_' . $treeClass . '_' . $model->getId();

            $content[] = $this->parseModel($model, $toggleID);

            if ($model->getMeta($model::HAS_CHILDREN) && $model->getMeta($model::SHOW_CHILDREN)) {
                $template = $this->getTemplate('dcbe_general_treeview_child');
                $subHtml  = '';

                foreach ($model->getMeta($model::CHILD_COLLECTIONS) as $childCollection) {
                    $subHtml .= $this->generateTreeView($childCollection, $treeClass);
                }

                $this
                    ->addToTemplate('select', $this->isSelectModeActive(), $template)
                    ->addToTemplate('objParentModel', $model, $template)
                    ->addToTemplate('strToggleID', $toggleID, $template)
                    ->addToTemplate('strHTML', $subHtml, $template)
                    ->addToTemplate('strTable', $model->getProviderName(), $template);

                $content[] = $template->parse();
            }
        }

        return \implode("\n", $content);
    }
protected function generateTreeView($collection, $treeClass)
    {
        $content = [];

        // Generate buttons - only if not in select mode!
        if (!$this->isSelectModeActive()) {
            (new ButtonRenderer($this->environment))->renderButtonsForCollection($collection);
        }

        foreach ($collection as $model) {
            /** @var ModelInterface $model */

            $toggleID = $model->getProviderName() . '_' . $treeClass . '_' . $model->getId();

            $content[] = $this->parseModel($model, $toggleID);

            if ($model->getMeta($model::HAS_CHILDREN) && $model->getMeta($model::SHOW_CHILDREN)) {
                $template = $this->getTemplate('dcbe_general_treeview_child');
                $subHtml  = '';

                foreach ($model->getMeta($model::CHILD_COLLECTIONS) as $childCollection) {
                    $subHtml .= $this->generateTreeView($childCollection, $treeClass);
                }

                $this
                    ->addToTemplate('select', $this->isSelectModeActive(), $template)
                    ->addToTemplate('objParentModel', $model, $template)
                    ->addToTemplate('strToggleID', $toggleID, $template)
                    ->addToTemplate('strHTML', $subHtml, $template)
                    ->addToTemplate('strTable', $model->getProviderName(), $template);

                $content[] = $template->parse();
            }
        }

        return \implode("\n", $content);
    }
protected function generateTreeView ( $ collection , $ treeClass ) { $ content = [ ] ; // Generate buttons - only if not in select mode! if ( ! $ this -> isSelectModeActive ( ) ) { ( new ButtonRenderer ( $ this -> environment ) ) -> renderButtonsForCollection ( $ collection ) ; } foreach ( $ collection as $ model ) { /** @var ModelInterface $model */ $ toggleID = $ model -> getProviderName ( ) . '_' . $ treeClass . '_' . $ model -> getId ( ) ; $ content [ ] = $ this -> parseModel ( $ model , $ toggleID ) ; if ( $ model -> getMeta ( $ model :: HAS_CHILDREN ) && $ model -> getMeta ( $ model :: SHOW_CHILDREN ) ) { $ template = $ this -> getTemplate ( 'dcbe_general_treeview_child' ) ; $ subHtml = '' ; foreach ( $ model -> getMeta ( $ model :: CHILD_COLLECTIONS ) as $ childCollection ) { $ subHtml .= $ this -> generateTreeView ( $ childCollection , $ treeClass ) ; } $ this -> addToTemplate ( 'select' , $ this -> isSelectModeActive ( ) , $ template ) -> addToTemplate ( 'objParentModel' , $ model , $ template ) -> addToTemplate ( 'strToggleID' , $ toggleID , $ template ) -> addToTemplate ( 'strHTML' , $ subHtml , $ template ) -> addToTemplate ( 'strTable' , $ model -> getProviderName ( ) , $ template ) ; $ content [ ] = $ template -> parse ( ) ; } } return \ implode ( "\n" , $ content ) ; }
Render the tree view and return it as string.

@param CollectionInterface $collection The collection to iterate over.
@param string              $treeClass  The class to use for the tree.

@return string
Render the tree view and return it as string .