Overriding Image widget

I have a custom NamedImageWidget that I am using in a Behavior. But now I'd like to use that widget for the Image field of the Image content type. Is there an easy way to specify a different widget for that field? As it is now, I'm practically having to recreate the Image type to do this, seems there should be an eaiser way.

Code if you're interested:
Custom widget: https://github.com/collective/collective.resourcemanager/blob/master/src/collective/resourcemanager/browser/widget.py
Used in a behavior: https://github.com/collective/collective.resourcemanager/blob/master/src/collective/resourcemanager/browser/behaviors.py#L23

@tkimnguyen got me pointed in the right direction, I needed to override the add and edit forms.

https://docs.plone.org/external/plone.app.dexterity/docs/advanced/custom-add-and-edit-forms.html

my custom edit class looks like this:

class ImageEdit(DefaultEditForm):

    def updateWidgets(self, prefix=None):
        super(ImageEdit, self).updateWidgets()
        image = self.widgets['image']
        image.__class__ = NamedRSImageWidget
        self.widgets.update()
2 Likes

Plone Foundation Code of Conduct