Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CKEditor not showing with Sonata Formatter (Sonata Admin Bundle)

I'm having troubles using the Sonata Formatter Bundle.

In my config.yml I have the following (amongst other stuff):

imports:
    - { resource: sonata.yml }

twig:
    debug:            "%kernel.debug%"
    strict_variables: "%kernel.debug%"

    #sonata
    form:
        resources:
            # ...
            - 'SonataFormatterBundle:Form:formatter.html.twig'

In my sonata.yml file I have:

sonata_block:
    default_contexts: [cms]
    blocks:
        # Enable the SonataAdminBundle block
        sonata.admin.block.admin_list:
            contexts:   [admin]
        # Your other blocks
        sonata.formatter.block.formatter:

sonata_formatter:
    formatters:
        markdown:
            service: sonata.formatter.text.markdown
            extensions:
                - sonata.formatter.twig.control_flow
                - sonata.formatter.twig.gist
        #        - sonata.media.formatter.twig #keep this commented unless you are using media bundle.


        text:
            service: sonata.formatter.text.text
            extensions:
                - sonata.formatter.twig.control_flow
                - sonata.formatter.twig.gist
        #        - sonata.media.formatter.twig


        rawhtml:
            service: sonata.formatter.text.raw
            extensions:
                - sonata.formatter.twig.control_flow
                - sonata.formatter.twig.gist
        #        - sonata.media.formatter.twig


        richhtml:
            service: sonata.formatter.text.raw
            extensions:
                - sonata.formatter.twig.control_flow
                - sonata.formatter.twig.gist
        #        - sonata.media.formatter.twig


        twig:
            service: sonata.formatter.text.twigengine
            extensions: [] # Twig formatter cannot have extensions

    ckeditor:
        templates:
            browser: 'SonataFormatterBundle:Ckeditor:browser.html.twig'
            upload: 'SonataFormatterBundle:Ckeditor:upload.html.twig'

ivory_ck_editor:
    configs:
        default:
            language:  '%locale%'
            toolbar: standard

sonata_admin:
    templates:
        layout:                 DXEenhanaBundle:Admin:standard_layout.html.twig

I've added the needed CSS and JS to my standard_layout.html.twig file and they are correctly loaded.

In my Admin file I have the following:

$formMapper
    ->add('name', 'text', array('label' => 'Applicant Name'))
    ->add('contacts', 'sonata_formatter_type', array(
        'event_dispatcher' => $formMapper->getFormBuilder()->getEventDispatcher(),
        'format_field'   => 'contacts',
        'source_field'   => 'contacts',
        'source_field_options'      => array(
            'attr' => array('class' => 'span10', 'rows' => 7)
        ),
        'ckeditor_context' => 'default',
        'listener'       => true,
        'target_field'   => 'contacts',
        'label' => 'Contacts'
    ))
    ...

I see a textarea but no ckeditor in my textarea, what am I missing? This is what I see in my browser: enter image description here

I'm also not getting any console errors or other errors ... .

like image 730
nielsv Avatar asked Dec 19 '22 02:12

nielsv


1 Answers

You need to overwrite the admin layout.html.twig template as described in the section Sonata Admin Integration of SonataFormatterBundle Documentation.

Create a new template file app\Resources\SonataAdminBundle\views\layout.html.twig:

{% extends 'SonataAdminBundle::standard_layout.html.twig' %}

{% block stylesheets %}
    {{ parent() }}

    <link rel="stylesheet" href="{{ asset('bundles/sonataformatter/markitup/skins/sonata/style.css') }}" type="text/css"
      media="all"/>
    <link rel="stylesheet" href="{{ asset('bundles/sonataformatter/markitup/sets/markdown/style.css') }}"
      type="text/css" media="all"/>
    <link rel="stylesheet" href="{{ asset('bundles/sonataformatter/markitup/sets/html/style.css') }}" type="text/css"
      media="all"/>
    <link rel="stylesheet" href="{{ asset('bundles/sonataformatter/markitup/sets/textile/style.css') }}" type="text/css"
      media="all"/>
{% endblock %}

{% block javascripts %}
    {{ parent() }}

    <script src="{{ asset('bundles/ivoryckeditor/ckeditor.js') }}" type="text/javascript"></script>
    <script src="{{ asset('bundles/sonataformatter/vendor/markitup-markitup/markitup/jquery.markitup.js') }}" type="text/javascript"></script>
    <script src="{{ asset('bundles/sonataformatter/markitup/sets/markdown/set.js') }}" type="text/javascript"></script>
    <script src="{{ asset('bundles/sonataformatter/markitup/sets/html/set.js') }}" type="text/javascript"></script>
    <script src="{{ asset('bundles/sonataformatter/markitup/sets/textile/set.js') }}" type="text/javascript"></script>
{% endblock %}

and update your config.yml with:

sonata_admin:
    templates:
        layout:  SonataAdminBundle::layout.html.twig
like image 191
lordrhodos Avatar answered Dec 21 '22 16:12

lordrhodos