Does anyone know if there is a sonata widget to show an HTML editor in the edit form? I'm thinking of using a custom template for that field which integrates an HTML, but I'm wondering if there's a better way to go.
2
votes
4 Answers
3
votes
1
votes
0
votes
I also used IvoryCKEditorBundle
After the initial setup in your project, you can use it easily as below:
use Ivory\CKEditorBundle\Form\Type\CKEditorType;
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('description', CKEditorType::class)
0
votes
Here is how you implement it: https://sonata-project.org/bundles/formatter/master/doc/reference/formatter_widget.html
My code example:
source_field -> body => existing entity field
format_field -> formattedBody => create new field in entity
target_field -> body => existing entity field
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('body', 'sonata_formatter_type', array(
'event_dispatcher' =>
$formMapper->getFormBuilder()->getEventDispatcher(),
'format_field' => 'formattedBody',
'format_field_options' => array(
'choices' => array('richhtml'),
'data' => 'richhtml',
),
'source_field' => 'body',
'source_field_options' => array(
'attr' => array(
'class' => 'span10',
'rows' => 20,
),
),
'listener' => true,
'target_field' => 'body',
))