Plone override the logo viewlet in plone 5.2 & 6


in this guide: Tutorial: Overriding Viewlets โ€” Plone Documentation v5.2

the code is:

class TitleViewlet(ViewletBase):
    index = ViewPageTemplateFile('')

    def update(self):

while in plone 5.2 and plone 6 the original code is:

class LogoViewlet(ViewletBase):
    index = ViewPageTemplateFile("")

    def update(self):
        super(LogoViewlet, self).update()

What is the right approach? Is the super part mandatory?

Possibly not since you derive from the same base class.

Yes, but calling .update() on the base class set some local properties. If I remove it:

AttributeError: 'LogoViewlet' object has no attribute 'portal_state'

the super update method does this:

def update(self):
    self.portal_state = getMultiAdapter(
        (self.context, self.request), name=u"plone_portal_state"
    self.site_url = self.portal_state.portal_url()
    self.navigation_root_url = self.portal_state.navigation_root_url()

Then you need to replicate the related code from the update() implementation

1 Like

The TitleViewlet should use super() as well. It currently redefines portal_state in at cc88fde5ec40ccec8d5128ee5db17f226125b661 ยท plone/ ยท GitHub.

As a rule of thumb: if the base class has a method you want to extend or use a return value from it, use super(); If you want to override it, don't.