survos / tree-bundle
incorporate jstree, using twig and stimulus and api-platform
Package info
Language:JavaScript
Type:symfony-bundle
pkg:composer/survos/tree-bundle
Fund package maintenance!
Requires
- php: ^8.5
- doctrine/doctrine-bundle: ^3.0
- doctrine/orm: ^3.4
- doctrine/persistence: ^4.1
- stof/doctrine-extensions-bundle: ^1.14
- survos/js-twig-bundle: ^2.5
- survos/kit-bundle: ^2.5
- symfony/config: ^8.1
- symfony/dependency-injection: ^8.1
- symfony/http-kernel: ^8.1
- symfony/options-resolver: ^8.1
- symfony/stimulus-bundle: ^3
- symfony/ux-twig-component: ^3
- tacman/twig-tree-tag: ^3.0.1
- twig/twig: ^3.4
Requires (Dev)
- api-platform/core: ^3.2||^4.0
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^13.0
- symfony/browser-kit: ^8.1
- symfony/framework-bundle: ^8.1
- symfony/phpunit-bridge: ^8.1
- symfony/twig-bundle: ^8.1
- symfony/var-dumper: ^8.1
This package is auto-updated.
Last update: 2026-06-20 12:40:01 UTC
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