我正在尝试在管理中添加格式化程序。
我安装了SonataAdminBundle
(工作正常)和SonataFormatterBundle
。
这是(部分)我的config.yml
sonata_block:
default_contexts: [cms]
blocks:
# enable the SonataAdminBundle block
sonata.admin.block.admin_list:
contexts: [admin]
sonata_formatter:
default_formatter: text
formatters:
markdown:
service: sonata.formatter.text.markdown
extensions:
- sonata.formatter.twig.control_flow
- sonata.formatter.twig.gist
- sonata.media.formatter.twig #keep this commented unless you are using media bundle.
text:
service: sonata.formatter.text.text
extensions:
- sonata.formatter.twig.control_flow
- sonata.formatter.twig.gist
- sonata.media.formatter.twig
rawhtml:
service: sonata.formatter.text.raw
extensions:
- sonata.formatter.twig.control_flow
- sonata.formatter.twig.gist
- sonata.media.formatter.twig
richhtml:
service: sonata.formatter.text.raw
extensions:
- sonata.formatter.twig.control_flow
- sonata.formatter.twig.gist
- sonata.media.formatter.twig
twig:
service: sonata.formatter.text.twigengine
extensions: [] # Twig formatter cannot have extensions
ckeditor:
templates:
browser: 'SonataFormatterBundle:Ckeditor:browser.html.twig'
upload: 'SonataFormatterBundle:Ckeditor:upload.html.twig'
ivory_ck_editor:
configs:
default:
language: '%locale%'
toolbar: standard
sonata_admin:
templates:
# default global templates
layout: SonataAdminBundle::layout.html.twig
在官方文档中,系统会要求layout.html.twig
添加app/Resources/SonataAdminBundle/views/
。在Symfony 3中,没有这样的路径,所以我创建了它。
在ArticleAdmin.php中,我添加了
->add('preview', 'sonata_simple_formatter_type', array('format' => 'richhtml', 'attr' => array('class' => 'ckeditor')))
我也试过
->add('preview', 'sonata_simple_formatter_type', array(
'format' => 'richhtml',
'ckeditor_context' => 'default', // optional
))
但它没有效果,我的预览字段中没有格式化程序。
我注意到“新”layout.html.twig
引用了bundles/sonataformatter/...
和bundles/ivoryckeditor/...
个文件,但ivoryckeditor
中没有sonataformatter
或web/bundles/
}。
可能是版本问题。所以,这是我的composer.json的“require”部分:
"require": {
"php": ">=5.5.9",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/orm": "^2.5",
"friendsofsymfony/rest-bundle": "^2.2",
"incenteev/composer-parameter-handler": "^2.0",
"nelmio/api-doc-bundle": "^2.13",
"sensio/distribution-bundle": "^5.0.19",
"sensio/framework-extra-bundle": "^3.0.2",
"sonata-project/admin-bundle": "^3.20",
"sonata-project/doctrine-orm-admin-bundle": "^3.1",
"sonata-project/easy-extends-bundle": "^2.2",
"sonata-project/formatter-bundle": "^3.2",
"sonata-project/google-authenticator": "^1.0",
"sonata-project/media-bundle": "^3.6",
"stof/doctrine-extensions-bundle": "^1.2.2",
"symfony/monolog-bundle": "^3.1.0",
"symfony/polyfill-apcu": "^1.0",
"symfony/swiftmailer-bundle": "^2.3.10",
"symfony/symfony": "3.3.*",
"twig/twig": "^1.0||^2.0"
谢谢,
答案 0 :(得分:1)
bin/console assets:install
我不确定你说的是哪个layout.html.twig,但它可能是standard_layout.html。您必须在AppBundle中添加此布局(如果您尚未覆盖SonataBundle)。
在我看来,布局的路径是:AppBundle/Resources/views/Admin/standard_layout.html.twig
在你的config.yml
中,你必须用你的一个代替标准的奏鸣曲布局:
sonata_admin:
title: 'Yor title'
templates:
## ...
layout: 'AppBundle::Admin/standard_layout.html.twig'
## ...