Sonata – add CKEditor in admin textareas

CKEditor is one of the best wysiwyg. It is possible to use CKEditor with sonataFormatterBundle, but there is an easier way to add CKEditor in Sonata admin textareas.
Add the file:

{% extends 'SonataAdminBundle:CRUD:base_edit.html.twig' %}

{% block javascripts %}
{{ parent() }}
    <script src="//"></script>
    <script type="text/javascript">
        $(function() {
{% endblock %}

It supposed that jquery is already loaded. If it’s not, add it in the block javascripts

in /app/config/config.yml, override the sonata edit file

    // ...
        edit:                AcmeAdminBundle:CRUD:edit.html.twig

Then in your admin file, in the configureFormFields function, use:

$formMapper->add('description', 'textarea', array('attr' => array('class' => 'ckeditor')));

Here, description is the entity field.

Sources :

Raphaël has written 45 articles

One thought on “Sonata – add CKEditor in admin textareas

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>