VEditor for Symfony
A bundle with a Twig function, routes for the editor files and the AI endpoint, and a sanitizer service in the container.
- Tested: 7.4 LTS
- Compatible code: 6.4–8
- PHP 8.2+
Installation in 3 steps
-
Install the bundle
From the VEditor Composer repository, then register it in
config/bundles.phpand import its routes.terminalcomposer require veditor/symfony-bundle # config/bundles.php: VEditor\Symfony\VEditorBundle::class => ['all' => true] -
Configure
Keys as in the server configuration, plus
styles,editor,filePickerUrl,uploadUrlandai.config/packages/veditor.yamlveditor: options: licenseKey: '%env(VEDITOR_LICENSE_KEY)%' aiApiKey: '%env(default::OPENAI_API_KEY)%' styles: - { name: Lead, element: p, classes: [lead] } -
Use in Twig
The
veditor()function renders the editor;VEditorService::sanitize()cleans the content on save.templates/article/edit.html.twig<form method="post"> {{ veditor('content', article.body, { height: '400px' }) }} <button>Save</button> </form> {# controller: $article->setBody($veditor->sanitize($request->request->get('content'))) #}
What you get
Integration features for Symfony, where you would expect them.
- Twig function
{{ veditor('content', article.body) }}, orrender()without Twig. - Editor files from the bundleRoute
veditor_assetwith the version in the address, only.jsand.css. - AI endpointRoute
veditor_aiwith its own CSRF token in the session andStreamedResponse; protect it withaccess_control. - Roles and limits
aiFeaturesUsing()gets the logged-in user,beforeAiRequestUsing()for limits. - Environment variablesLicence and API keys through
%env()%, never in the repository. - CSP nonceFrom the
csp_noncerequest attribute or the fourth argument ofveditor().
Try it in your browser
The demo has the full toolbar and shows what the PHP sanitizer returns for your content.
All integrations
-
Laravel
Composer package Tested: 12 Compatible code: 11–13 -
Symfony
Symfony bundle Tested: 7.4 LTS Compatible code: 6.4–8 -
Yii2
Code to copy Tested: 2.0.55 -
PHP
Without a framework PHP 8.1+ -
React
npm package Tested: 18 Compatible code: 17+ -
Vue 3
npm package Tested: 3.5 Compatible code: 3.2+ -
Your file manager
Editor hooks
Names and trademarks belong to their owners. Their use does not imply partnership.