Search code examples
symfonysonata-adminsymfony-sonatasonata

sonata admin add richhtml editor to block content


I'd like to add ckeditor to content field in block admin. Here's what i did till now:

  1. added raw_content and content_formatter properties to my block
  2. modified buildEditForm in TextBlockService to this:

    public function buildEditForm(FormMapper $formMapper, BlockInterface $block)
    {
    $formMapper->add('settings', 'sonata_type_immutable_array', array(
        'keys' => array(
            array('content', 'sonata_formatter_type', array(
                'event_dispatcher' => $formMapper->getformBuilder()->getEventDispatcher(),
                'format_field'   => ['content_formatter'],
                'source_field'   => ['raw_content'],
                'source_field_options'      => array(
                    'attr' => array('class' => 'span10', 'rows' => 10)
                ),
                'listener'       => true,
                'target_field'   => ['content']
            )),
        )
    ));
    }
    

It works just fine, allowing me to choose 'richhtml' from editors list but when i try to save the block it throws an error:

Expected argument of type "string or Symfony\Component\PropertyAccess\PropertyPathInterface", "NULL" given 

How can i fix that?


Solution

  • here's how it should be to work:

    $formMapper->add('settings', 'ckeditor', array());