I'm trying to use 'sonata_formatter_type' with sonata admin without success. The docs maybe are missing some step. I want to use ckeditor.
new Sonata\FormatterBundle\SonataFormatterBundle(),
new Ivory\CKEditorBundle\IvoryCKEditorBundle(),
ivory_ck_editor:
default_config: my_config
configs:
my_config:
language: '%locale%'
toolbar: [ [ "Bold", "Italic", "Underline", "FontSize", 'TextColor'], [ "NumberedList",'BulletedList', 'JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'], [ 'Outdent','Indent' ], [ 'Link','Unlink','Anchor' ], [ 'Cut','Copy','Paste','-','Undo','Redo'] ]
sonata_formatter:
formatters:
markdown:
service: sonata.formatter.text.markdown
extensions:
- sonata.formatter.twig.control_flow
- sonata.formatter.twig.gist
text:
service: sonata.formatter.text.text
extensions:
- sonata.formatter.twig.control_flow
- sonata.formatter.twig.gist
rawhtml:
service: sonata.formatter.text.raw
extensions:
- sonata.formatter.twig.control_flow
- sonata.formatter.twig.gist
richhtml:
service: sonata.formatter.text.raw
extensions:
- sonata.formatter.twig.control_flow
- sonata.formatter.twig.gist
twig:
form:
resources:
- 'SonataFormatterBundle:Form:formatter.html.twig'
->add('myfield', 'sonata_formatter_type', array(
'event_dispatcher' => $formMapper->getFormBuilder()->getEventDispatcher(),
'format_field' => 'myfield',
'source_field' => 'myfield',
'ckeditor_context' => 'my_config',
'source_field_options' => array(
'attr' => array('class' => 'span10', 'rows' => 7)
),
'listener' => true,
'target_field' => 'myfield'
))
<div id="sonata-ba-field-container-s54084950b132f_myfield" class="form-group">
<label class="control-label required">
myfield
</label>
<div class=" sonata-ba-field sonata-ba-field-standard-natural ">
<div style="margin-bottom: 5px;">
<textarea rows="7" class="span10 form-control" required="required" name="s54084950b132f[myfield][myfield]" id="s54084950b132f_myfield_myfield"></textarea>
</div>
<script>
var s54084950b132f_myfield_rich_instance = false;
jQuery(document).ready(function() {
// This code requires CKEDITOR and jQuery MarkItUp
if (typeof CKEDITOR === 'undefined' || jQuery().markItUp == undefined) {
return;
}
jQuery('#s54084950b132f_myfield_myfield').parents("form").on('click', function(event) {
if (s54084950b132f_myfield_rich_instance) {
s54084950b132f_myfield_rich_instance.updateElement();
}
});
jQuery('#s54084950b132f_myfield_myfield').change(function(event) {
var elms = jQuery('#s54084950b132f_myfield_myfield');
elms.markItUpRemove();
if (s54084950b132f_myfield_rich_instance) {
s54084950b132f_myfield_rich_instance.destroy();
}
var val = jQuery(this).val();
var appendClass = val;
switch (val) {
case 'textile':
elms.markItUp(markitup_sonataTextileSettings);
break;
case 'markdown':
elms.markItUp(markitup_sonataMarkdownSettings);
break;
case 'bbcode':
elms.markItUp(markitup_sonataBBCodeSettings);
break;
case 'rawhtml':
elms.markItUp(markitup_sonataHtmlSettings);
appendClass = 'html';
break;
case 'richhtml':
s54084950b132f_myfield_rich_instance = CKEDITOR.replace("s54084950b132f_myfield_myfield", {"toolbar": [["Bold", "Italic", "Underline", "FontSize", "TextColor"], ["NumberedList", "BulletedList", "JustifyLeft", "JustifyCenter", "JustifyRight", "JustifyBlock"], ["Outdent", "Indent"], ["Link", "Unlink", "Anchor"], ["Cut", "Copy", "Paste", "-", "Undo", "Redo"]], "language": "pt_BR"});
;
}
var parent = elms.parents('div.markItUp');
if (parent) {
for (name in ['textile', 'markdown', 'bbcode', 'rawhtml', 'richhtml', 'rawhtml']) {
parent.removeClass(name)
}
parent.addClass(appendClass);
}
});
jQuery('#s54084950b132f_myfield_myfield').trigger('change');
});
</script>
</div>
</div>
Am I missing something? Add some JS, CSS,...