我在使用Sonata Formatter Bundle时遇到了麻烦。
在我的 config.yml 中,我有以下内容(以及其他内容):
imports:
- { resource: sonata.yml }
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
#sonata
form:
resources:
# ...
- 'SonataFormatterBundle:Form:formatter.html.twig'
在我的 sonata.yml 文件中,我有:
sonata_block:
default_contexts: [cms]
blocks:
# Enable the SonataAdminBundle block
sonata.admin.block.admin_list:
contexts: [admin]
# Your other blocks
sonata.formatter.block.formatter:
sonata_formatter:
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:
layout: DXEenhanaBundle:Admin:standard_layout.html.twig
我已将所需的CSS和JS添加到我的 standard_layout.html.twig 文件中,并且它们已正确加载。
在我的管理文件中,我有以下内容:
$formMapper
->add('name', 'text', array('label' => 'Applicant Name'))
->add('contacts', 'sonata_formatter_type', array(
'event_dispatcher' => $formMapper->getFormBuilder()->getEventDispatcher(),
'format_field' => 'contacts',
'source_field' => 'contacts',
'source_field_options' => array(
'attr' => array('class' => 'span10', 'rows' => 7)
),
'ckeditor_context' => 'default',
'listener' => true,
'target_field' => 'contacts',
'label' => 'Contacts'
))
...
我在textarea看到了textarea但没有ckeditor,我错过了什么? 这是我在浏览器中看到的:
我也没有收到任何控制台错误或其他错误......
答案 0 :(得分:6)
您需要覆盖管理layout.html.twig模板,如Sonata Admin Integration of SonataFormatterBundle Documentation部分所述。
创建新模板文件app\Resources\SonataAdminBundle\views\layout.html.twig
:
{% extends 'SonataAdminBundle::standard_layout.html.twig' %}
{% block stylesheets %}
{{ parent() }}
<link rel="stylesheet" href="{{ asset('bundles/sonataformatter/markitup/skins/sonata/style.css') }}" type="text/css"
media="all"/>
<link rel="stylesheet" href="{{ asset('bundles/sonataformatter/markitup/sets/markdown/style.css') }}"
type="text/css" media="all"/>
<link rel="stylesheet" href="{{ asset('bundles/sonataformatter/markitup/sets/html/style.css') }}" type="text/css"
media="all"/>
<link rel="stylesheet" href="{{ asset('bundles/sonataformatter/markitup/sets/textile/style.css') }}" type="text/css"
media="all"/>
{% endblock %}
{% block javascripts %}
{{ parent() }}
<script src="{{ asset('bundles/ivoryckeditor/ckeditor.js') }}" type="text/javascript"></script>
<script src="{{ asset('bundles/sonataformatter/vendor/markitup-markitup/markitup/jquery.markitup.js') }}" type="text/javascript"></script>
<script src="{{ asset('bundles/sonataformatter/markitup/sets/markdown/set.js') }}" type="text/javascript"></script>
<script src="{{ asset('bundles/sonataformatter/markitup/sets/html/set.js') }}" type="text/javascript"></script>
<script src="{{ asset('bundles/sonataformatter/markitup/sets/textile/set.js') }}" type="text/javascript"></script>
{% endblock %}
并使用以下内容更新 config.yml
sonata_admin:
templates:
layout: SonataAdminBundle::layout.html.twig
答案 1 :(得分:3)
对你来说可能有点太晚了,但我遇到了同样的问题。我不得不在这个领域添加一个“ckeditor”课程:
->add('htmlContent', 'sonata_simple_formatter_type', array('format' => 'richhtml', 'attr' => array('class' => 'ckeditor')))
这使它发挥作用
答案 2 :(得分:0)
自SonataAdmin#v0.3起,您可以在配置文件中添加资产。 Formatter Docs
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
print("finish to load")
if webView.url!.absoluteString.range(of: "ADD_STRING_TO_BE_CHECKED_HERE") != nil
{
print("Success")
//DO WHAT YOU NEED HERE
}
}
sonata_admin.yaml