Sonata管理软件包中的HTML编辑器
答
在项目初始设置后,就可以轻松地使用它,如下:
use Ivory\CKEditorBundle\Form\Type\CKEditorType;
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('description', CKEditorType::class)
答
下面是如何实现它:https://sonata-project.org/bundles/formatter/master/doc/reference/formatter_widget.html
我的代码示例:
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',
))