How to show content type icons in portal-globalnav?

In listings and in the navigationportlet we can configure whether the content type icons should be shown or not.

Is it possible to show content type icons in portal-globalnav?

Not that I know of.
We had a pretty similar usecase we solved with : collective.iconifiednavigation · PyPI

Maybe this can help ...

You could add CSS classes and add them with CSS (or maybe add the same css classes that are used elsewhere:

I THINK the code would be something like

plone.app.layout/viewlets/common.py

In GlobalsectionViewlet:

u'<a href="{url}" class="contenttype-{typpe} state-{review_state}"{aria_haspopup}>{title}{opener}'

in def navtree:

        if "typpe" not in entry:
            entry["typpe"] = "unknown"

In 'entry' (about line 350)

            "typpe" : brain.portal_type

(or maybe brain.Type)

PS: I used typpe just to be sure I would not 'mess up something already present (portal_type or type), change it if you want to…

UPDATE: I tested and it works if you make portal_type lowercase ( brain.portal_type.lower(). You need to add an CSS entry for 'unknown' or you will get the default 'puzzle-icon'

@espenmn: Thanks for your hint! I solved it as follows:

class MyGlobalSectionsViewlet(GlobalSectionsViewlet):
    index = ViewPageTemplateFile("mysections.pt")

    def __init__(self, context, request, view, manager=None):
        super().__init__(context, request, view, manager=None)
        self._item_markup_template = (
            u'<li class="{id}{has_sub_class}">'
            u'<a href="{url}" class="contenttype-{portal_type} state-{review_state}"{aria_haspopup}>{title}</a>{opener}'
            u"{sub}"
            u"</li>"
        )

    @property
    @memoize
    def portal_tabs(self):
        portal_tabs_view = getMultiAdapter(
            (self.context, self.request), name="my_portal_tabs_view"
        )
        return portal_tabs_view.topLevelTabs()

    def customize_tab(self, entry, tab):
        entry.update({"portal_type": normalizeString(tab["portal_type"])})

    def customize_entry(self, entry, brain):
        entry.update({"portal_type": normalizeString(brain.portal_type)})

Then I added the following for the portal_tabs to get the portal_type

class MyCatalogNavigationTabs(CatalogNavigationTabs):
    def customize_entry(self, entry, brain=None):
        if brain:
            entry.update({"portal_type": brain.portal_type})
        else:
            entry.update({"portal_type": UNKNOWN_PORTAL_TYPE})

and configured as follows

    <browser:viewlet
            name="my_global_sections"
            manager="plone.app.layout.viewlets.interfaces.IMainNavigation"
            class=".sections.MyGlobalSectionsViewlet"
            layer="hmwk.barceloneta.interfaces.IHmwkBarcelonetaLayer"
            permission="zope2.View"
    />
    <browser:page
            for="*"
            name="my_portal_tabs_view"
            class=".sections.MyCatalogNavigationTabs"
            permission="zope.Public"
            allowed_attributes="topLevelTabs"
            layer="hmwk.barceloneta.interfaces.IHmwkBarcelonetaLayer"
    />