4

I'm creating some custom content types using dexterity. I would like to "customize" the aspect of a RichText Field allowing only basic buttons of TinyMce on this field.

In Archetypes I could use

TextField('text',
allowable_content_types=('text/html',),
default_output_type='text/x-html-safe',
required=1,
widget=RichWidget
(label='Content',
    allow_buttons=(
    'bold',
    'italic',
    'justifyleft',
    'justifyright',
    ),
),),

How would I do this with Dexerity based contenttypes?

Ida
  • 3,994
  • 21
  • 40
Vito
  • 1,201
  • 1
  • 10
  • 16
  • I guess it would be possible to simply hide/disable the unwanted buttons clientside with some javascript, since the buttons are marked with an id including the fieldname. But I'm not quite sure what would be a good way of achieving this, where to do it, etc. - anyone have any ideas on this method? – sunew May 03 '15 at 23:54

1 Answers1

1

There doesn't appear to be a "nice" way to do this right now. Even the Plone docs are currently at a loss. http://docs.plone.org/develop/plone/forms/wysiwyg.html#id9

The problem lies with Products.TinyMCE trying to get the WYSIWYG configuration from the widget attribute of the Field.

https://github.com/plone/Products.TinyMCE/blob/1.3.6/Products/TinyMCE/utility.py#L711-L713

# Get widget attributes
widget = getattr(field, 'widget', None)
filter_buttons = getattr(widget, 'filter_buttons', None)
allow_buttons = getattr(widget, 'allow_buttons', None)

But, as I understand, with Dexterity we instead map fields to widgets on the form object.

from plone.autoform import directives as form
from plone.app.z3cform.wysiwyg import WysiwygFieldWidget

class IExample(model.schema):
    form.widget('body', WysiwygFieldWidget)
    body = schema.Text(title=u"Body")

So, our body field possesses no widget attribute from which Products.TinyMCE can extract configurations.

At any rate, if you need it to work right now, I was able to hack it by doing the following:

In your ZMI, customize portal_skins/tinymce/tinymce_wysiwyg_support to change the line field field|nothing to field field|view/field|nothing.

Define your content type in a schema-driven fashion, and for your WYSIWYG field do the following:

class mywidg(object):
    allow_buttons = ('bold',
                     'italic',
                     'justifyright',
                     'justifyleft',)

class IExample(model.schema):
    form.widget('body', WysiwygFieldWidget)
    body = schema.Text(title=u"Body")
    body.widget = mywidg()
Travv15
  • 243
  • 1
  • 6
  • That looks promising. Curious about Vito's feedback. If it works, you'll have an upvote for sure. – Ida Nov 27 '14 at 06:34
  • It's a good idea. I'll test it tomorrow, or next monday. Thank's a lot – Vito Nov 28 '14 at 21:34
  • I noticed today that my change to wysiwyg_support broke TinyMCE on Archetypes. I moved the change to the tinymce_wysiwyg_support macro, and things seem to be working as expected. – Travv15 Dec 04 '14 at 17:05