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+
Symfony form with VEditor rendered by the veditor() Twig function

Installation in 3 steps

  1. Install the bundle

    From the VEditor Composer repository, then register it in config/bundles.php and import its routes.

    terminal
    composer require veditor/symfony-bundle
    # config/bundles.php: VEditor\Symfony\VEditorBundle::class => ['all' => true]
  2. Configure

    Keys as in the server configuration, plus styles, editor, filePickerUrl, uploadUrl and ai.

    config/packages/veditor.yaml
    veditor:
        options:
            licenseKey: '%env(VEDITOR_LICENSE_KEY)%'
            aiApiKey: '%env(default::OPENAI_API_KEY)%'
            styles:
                - { name: Lead, element: p, classes: [lead] }
  3. 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.

Full integration documentation

  • Twig function{{ veditor('content', article.body) }}, or render() without Twig.
  • Editor files from the bundleRoute veditor_asset with the version in the address, only .js and .css.
  • AI endpointRoute veditor_ai with its own CSRF token in the session and StreamedResponse; protect it with access_control.
  • Roles and limitsaiFeaturesUsing() gets the logged-in user, beforeAiRequestUsing() for limits.
  • Environment variablesLicence and API keys through %env()%, never in the repository.
  • CSP nonceFrom the csp_nonce request attribute or the fourth argument of veditor().

Try it in your browser

The demo has the full toolbar and shows what the PHP sanitizer returns for your content.