from plone import api
from ploneintranet.layout.viewlets.common import PIPathBarViewlet


class NewsEditPathBarViewlet(PIPathBarViewlet):
    def update(self):
        """Fix the breadcrumbs to point to the publisher view when appropriate"""
        super().update()
        app = api.portal.get().get("news")
        if not app:
            return
        app_url = app.absolute_url()
        for breadcrumb in self.breadcrumbs:
            if breadcrumb["absolute_url"] == app_url:
                breadcrumb["absolute_url"] += "/@@publisher"
