Discuss your project
Partitech Sonata Extra Bundle

Sonata Extra Bundle: media library for CKEditor

Introduction An appropriate configuration of CKEditor is essential for its optimal functioning. This guide provides the steps to install a valid version of CKEditor and configure it to use the Media library in a Sonata project. Installation Resolution of i...

Contrôles de compatibilité Symfony et Sonata

Introduction

An appropriate configuration of CKEditor is essential for its optimal functioning. This guide provides the steps to install a valid version of CKEditor and configure it to use the Media library in a Sonata project.

Installation

Resolution of invalid LTS license key error

If you encounter the following error:


[CKEDITOR] For more information about this error go to https://ckeditor.com/docs/ckeditor4/latest/guide/dev_errors.html#invalid-lts-license-key

Install the specified version of CKEditor:


php php php bin/console ckeditor:install --tag=4.19.0
php bin/console assets:install

Configuration for the media library

To integrate the media library with CKEditor, you must specify filebrowserBrowseRoute and filebrowserImageBrowseRoute. Use the road sonata_extra_ckeditor_media_browser to this effect.

Here is an example of a configuration:


fos_ck_editor:
    default_config: default
    base_path: "build/ckeditor"
    js_path:   "build/ckeditor/ckeditor.js"
    configs:
        default:
            language: fr
            # default toolbar plus Format button
            toolbar:
                - [Bold, Italic, Underline, -, Cut, Copy, Paste,
                   PasteText, PasteFromWord, -, Undo, Redo, -,
                   NumberedList, BulletedList, -, Outdent, Indent, -,
                   Blockquote, -, Image, Link, Unlink, Table]
                - [Format, Maximize, Source]

            enterMode: CKEDITOR.ENTER_BR
            filebrowserBrowseRoute: sonata_extra_ckeditor_media_browser
            filebrowserImageBrowseRoute: sonata_extra_ckeditor_media_browser


Symfony and Sonata compatibility checks

Adapt the example to the installed version

The Symfony and Sonata examples remain tied to the versions indicated in the article. Symfony 4.x and Symfony 6.2 are no longer maintained: for a current project, use a maintained branch and the documentation that exactly matches your dependencies.

php bin/console about
composer show symfony/framework-bundle sonata-project/admin-bundle

Before resuming the code, check the signatures, services, routes, and templates concerned. Then add a functional test covering permissions, HTTP code, and the visible result.

Reference: maintained Symfony versions.

Share this article