2016-07-04 43 views
4

我正在使用Plone 5.0安装程序,并且希望以某种方式对其进行修改,以便希望创建新页面的用户在其TinyMCE编辑器中具有默认文本。将缺省内容添加到Plone 5.0中的tinyMCE

我对Plone相当陌生,并且对不同语言的数量以及它们如何互相连接有点不知所措。因此,我不希望快速而肮脏地处理某些文件,而是希望得到一些关于如何正确有效地开始解决问题的建议。

任何建议,如何工作,是值得欢迎的。

回答

4

前端(在这种情况下为TinyMCE)不对默认值负责,它是下面的形式。

Plone 5使用z3c形式的敏捷类型。


编辑:这是你怎么做这个老派的方式 - 我指的是Plone的指令方式 - Sry基因误导你。我仍然使用plone.directives,它支持这种默认值适配器。

plone.app.contenttypes的默认内容类型Document正在使用plone.supermodel。这有一个不同的概念。

如果你仍愿意创建自己的富文本的行为就可以按照这些指示:http://docs.plone.org/external/plone.app.dexterity/docs/advanced/defaults.html

你的情况:

def richtext_default_value(**kwargs): 
    return RichTextValue('<p>Some text</p>') 


@provider(IFormFieldProvider) 
class IRichText(model.Schema): 

    text = RichTextField(
     title=_(u'Text'), 
     description=u"", 
     required=False, 
     defaultFactory=richtext_default_value, 
    ) 
    model.primary('text') 

您可以将defaultFactory添加到文本字段。

如果你在你的蛋上破解了这些行,它就会起作用。


下面是有关以编程方式设置默认值的一些信息:

所以你的情况,这可能是这个样子:

from plone.directives.form import default_value 
from plone.app.contenttypes.behaviors.richtext import IRichText 
from plone.app.textfield.value import RichTextValue 

@default_value(field = IRichText['text']) 
def richtext_default_value(data): 
    return RichTextValue('<p>Some text</p>') 

您可以通过context参数延长DEFAULT_VALUE装饰更具体:@default_value(field = IRichText['text'], context=my.package.content.interfaces.IMyType)

但由于我们有行为的概念,它可能是更好的默认值来实现自己的富文本的行为:

  1. 创建行为 - >http://docs.plone.org/external/plone.app.dexterity/docs/behaviors/creating-and-registering-behaviors.html并将plone默认的richtext行为作为您自己的模板 - >https://github.com/plone/plone.app.contenttypes/blob/1.2.16/plone/app/contenttypes/behaviors/richtext.py
  2. 删除'plone.app.contenttypes.behaviors.richtext。IRichText`从您的内容类型(文档)到ZMI(portal_types - > Document)的行为
  3. 添加您自己的Richtext行为,这可能类似于my.package.behaviors.richtext.IRichtextWithDefaultValue
+0

感谢您的有用建议。我想通过将其插入到我的“行为”文件夹中的'richtext.py'来测试您的解决方案。它似乎没有生效。但我不知道我是否一直在正确的文件夹中。它是'buildout-cache'中的'.egg'文件夹。我走错路了吗? – Waynebird

+0

@Waynebir:你可以在线发布你的代码(例如github回购)吗? 除此之外,我建议你在http://training.plone.org/5进行培训,这样你就可以理解在哪里。 –

+1

我更新了一些关于plone.supermodel的信息,以及实现文本字段默认值的另一种方式。 – Mathias