Reputation: 227
I am working on a Plone 5.0 setup and I want to modify it in a way, so that users, who wants to create a new page, have a default text in their TinyMCE editor.
I am quite new to Plone and a bit overwhelmed by the amount of different languages and how they interconnect with each other. So instead of working on some files quick and dirty, I would like to have some suggestions how to start working on the problem properly and efficient.
Any suggestions, how to work on that are welcome.
Upvotes: 4
Views: 168
Reputation: 6839
The front-end (in this case TinyMCE) is not responsible for the default value, it's the form beneath.
Plone 5 uses Dexterity types with z3c forms.
EDIT: This is how your doing this the old school way - I mean the plone directives way -
Sry for misleading you. I still use plone.directives
, which supports this kind of default value adapter.
The default content type Document
of plone.app.contenttypes is using plone.supermodel. This has a different concept.
If you are still willing to create your own Richtext behavior you may follow those instructions: http://docs.plone.org/external/plone.app.dexterity/docs/advanced/defaults.html
In your case:
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')
You can add a defaultFactory
to the text field.
If you hack those lines on your egg, it will work.
Here's some information about setting a default value programmatically:
So in your case this may look something like this:
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>')
You may extend the default_value decorator by context
parameter to be more specific: @default_value(field = IRichText['text'], context=my.package.content.interfaces.IMyType)
BUT since we have the concept of behaviors it's may be better to implement your own Richtext behavior with a default value:
my.package.behaviors.richtext.IRichtextWithDefaultValue
. Upvotes: 4