survos/tree-bundle
最新稳定版本:2.2.2
Composer 安装命令:
composer require survos/tree-bundle
包简介
incorporate jstree, using twig and stimulus and api-platform
README 文档
README
Tree UI + API editing for Symfony UX Twig Components.
This bundle provides:
apiTreeBrowser/api_treeTwig components (jsTree-backed)@survos/tree-bundle/api_treeStimulus controller{% tree %}Twig tag for recursive rendering
Install
composer require survos/tree-bundle
Required JS modules (important)
apiTreeBrowser can render embedded Twig blocks in the browser. For this to work reliably, your importmap must include:
@tacman1123/twig-browser@tacman1123/twig-browser/adapters/symfony@tacman1123/twig-browser/src/compat/compileTwigBlocks.js@survos/js-twig/generated/fos_routes.js(forpath()in client-side twig)
If these are missing or incompatible, the controller now fails fast with a clear error instead of silently falling back.
Minimal Example
<twig:apiTreeBrowser :resourceClass="topicClass" :filter="{ tenantId: tenant.code }" :editable="true" :openAll="true" :caller="_self" > <twig:block name="nodeLabel"> {{ node.name ?? node.title ?? node.code ?? node.id }} </twig:block> <twig:block name="api_tree_content"> {% set item = record ?? node %} <h5>{{ item.name ?? item.title ?? item.id }}</h5> </twig:block> </twig:apiTreeBrowser>
Variables available inside client-side Twig blocks
Inside nodeLabel / api_tree_content, these render vars are available:
node- selected jsTree node payloadrecord- full fetched API record for selected nodeitem- alias ofrecord ?? nodehydra- alias ofitemglobals- values passed from component:globals="..."
If you pass tenant info via globals, reference globals.tenantId (not tenantId directly).
Example:
{% set params = { tenantId: globals.tenantId, instanceId: item.id } %}
<a href="{{ path('instance_browse', params) }}">Browse</a>
Styling hooks (Tabler/Bootstrap/custom)
Use component class options:
browserClasstreePaneClasscontentPaneClassstyle="plain"to avoid the built-in bootstrap grid wrapper
Wrapper includes api-tree-browser--themeable for easy theming.
Example:
<twig:apiTreeBrowser style="plain" browserClass="my-tree-layout" treePaneClass="my-tree-column" contentPaneClass="my-content-column" ... />
Toolbar buttons
Built-in toolbar includes search and clear.
Optional slideshow button appears when you pass:
:globals="{ slideshowUrl: '/my/slideshow/url' }"
API controller defaults
Bundle config now supports separate controllers:
survos_tree: tree_stimulus_controller: '@survos/tree/tree' api_tree_stimulus_controller: '@survos/tree/api_tree'
Legacy stimulus_controller is deprecated.
Performance behavior
- Tree list loads from collection endpoint once.
- Full detail
GET {id}fetch happens on explicit node selection. - Label rendering uses already-loaded collection data.
Troubleshooting
-
Error:
Twig function path is not configured- Ensure
@survos/js-twig/generated/fos_routes.jsis mapped in importmap. - Ensure
var/js_twig_bundle/generated/fos_routes.jsexists (cache warmer). - Ensure
@tacman1123/twig-browser,@tacman1123/twig-browser/adapters/symfony, and@tacman1123/twig-browser/src/compat/compileTwigBlocks.jsare mapped.
- Ensure
-
Detail block cannot see
tenantId- Use
globals.tenantIdunless you explicitly flatten into top-level context.
- Use
统计信息
- 总下载量: 2.5k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-07-25