Jerry Pham
Jerry Pham

Reputation: 372

SonataAdminBundle formMapper richtext

As title, could anybody help me the way to create a form with richtext content?

This is textarea for form but I dont know how to make it richtext editor:

$formMapper->add('settings', 'sonata_type_immutable_array', array(
        'keys' => array(
            array('content', 'textarea', array()),
        )
    ));

Thanks

Upvotes: 0

Views: 498

Answers (1)

Yoann Chambonnet
Yoann Chambonnet

Reputation: 1333

Then you should create your custom form type that would extend the sonata_type_immutable_array by specifying the "getParent" function as follow

public function getParent()
{
    return 'sonata_type_immutable_array';
}

From there, in the "setDafaults" method, you can do something like

public function setDefaultOptions(OptionsResolverInterface $resolver)
{
    $resolver->setDefaults(array(
        'attr' => array(
            'class' => 'richtext',
        )
    ));
}

Now, in your javascript that initializes your richtext editor, you can look for your "richtext" class (with jQuery for example) and then initialize the editor.

For example with CKeditor :

CKEDITOR.replace( 'richtext', {
    customConfig: ''
});

AND IF you don't know how to include Javascript files / libraries, you should consider having a look at this part of the official documentation

EDIT :

and of course use it with your formmapper directly as you would use any custom form type.

Upvotes: 1

Related Questions