public function indexAction(Request $request)
    {
        $id = $request->get('id');
        $version = $request->get('version');
        $mode = $request->get('mode', 'edit');

        $elementtypeService = $this->get('phlexible_elementtype.elementtype_service');

        $elementtype = $elementtypeService->findElementtype($id);
        $elementtypeStructure = $elementtype->getStructure();

        $rootNode = $elementtypeStructure->getRootNode();
        $type = $elementtype->getType(); // != 'reference' ? 'root' : 'referenceroot';

        $children = [];
        $rootDsId = '';
        $rootType = 'root';
        if ($rootNode) {
            $rootDsId = $rootNode->getDsId();
            $rootType = $rootNode->getType();
            $children = $elementtypeStructure->getChildNodes($rootNode->getDsId());
        }

        $language = $this->getUser()->getInterfaceLanguage('en');
        if (!$language) {
            $language = 'en';
        }

        $data = [
            [
                'text' => $elementtype->getTitle($language)
                    .' [v'.$elementtype->getRevision().', '
                    .$elementtype->getType().']',
                'id' => md5(serialize($rootNode)),
                'ds_id' => $rootDsId,
                'element_type_id' => $elementtype->getId(),
                'element_type_version' => $elementtype->getRevision(),
                'icon' => '/bundles/phlexibleelementtype/elementtypes/'.$elementtype->getIcon(),
                'cls' => 'p-elementtypes-type-'.$type,
                'leaf' => false,
                'expanded' => true,
                'type' => $rootType,
                'allowDrag' => ($type === Elementtype::TYPE_REFERENCE),
                'allowDrop' => $mode === 'edit',
                'editable' => $mode === 'edit',
                'properties' => [
                    'root' => [
                        'title' => $elementtype->getTitle($language),
                        'reference_title' => $elementtype->getTitle($language)
                            .' [v'.$elementtype->getRevision().']',
                        'unique_id' => $elementtype->getUniqueId(),
                        'icon' => $elementtype->getIcon(),
                        'hide_children' => $elementtype->getHideChildren() ? 'on' : '',
                        'default_tab' => $elementtype->getDefaultTab(),
                        'default_content_tab' => $elementtype->getDefaultContentTab(),
                        'type' => $type,
                        'template' => $elementtype->getTemplate(),
                        'metaset' => $elementtype->getMetaSetId(),
                        'comment' => $elementtype->getComment(),
                    ],
                    'mappings' => $elementtype->getMappings(),
                ],
                'children' => $this->recurseTree(
                    $elementtypeStructure,
                    $children,
                    $language,
                    $mode,
                    false,
                    true
                ),
            ],
        ];

        return new JsonResponse($data);
    }