Customizing Widget Used On Existing Content Types
Situation
You are using a type provided by plone that uses archetypes and you do not like a particular widget the archetypes has implemented for the field. You need to make a custom widget only for that type. Problem is that you cannot override the widget page template file, because the type is registered with specifically that widget and overriding won't work.
To accomplish this task, you need to override the content type definition and create a new widget that is based off the old widget.
Solution
- Decide what widget you need to customize. In this case, I'm customizing the InAndOut widget for the Smart Folder Type.
- Copy the inandout.pt file(or widget page template file you are customizing) from the Products/Archetypes/skins/widgets folder into your skins directory and rename as needed.
- Make customizations to widget page template file.
- In your install script you are going to need to override the value for the "macro" attribute for the widget in the field of your schema that you want to change.
- Then
you'll need to re-register the content type(you'll need to look at the
content type definitely to do this most likely because you need to know
the field name).
- In the case of the smart folder, it would look like this,
from Products.ATContentTypes.content.topic import ATTopic from Products.ATContentTypes.config import PROJECTNAME from Products.ATContentTypes.content.base import registerATCT topic_fields = ATTopic.schema.fields() for field in topic_fields: if field.getName() == 'customViewFields': field.widget.macro = "my_inandout" registerATCT(ATTopic, PROJECTNAME)