Skip to content

Commit

Permalink
Use @@iconresolver to display icons in navigation portlet
Browse files Browse the repository at this point in the history
  • Loading branch information
pbauer committed Apr 6, 2022
1 parent 6f888f9 commit d7fe54d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
16 changes: 0 additions & 16 deletions plone/app/portlets/portlets/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,22 +369,6 @@ def thumb_scale(self):
thumb_scale_portlet = settings.thumb_scale_portlet
return thumb_scale_portlet

def getMimeTypeIcon(self, node):
try:
if not node["normalized_portal_type"] == "file":
return None
fileo = node["item"].getObject().file
portal_url = getNavigationRoot(self.context)
mtt = getToolByName(self.context, "mimetypes_registry")
if fileo.contentType:
ctype = mtt.lookup(fileo.contentType)
if not ctype:
return None
return os.path.join(portal_url, guess_icon_path(ctype[0]))
except AttributeError:
return None
return None

def update(self):
pass

Expand Down
11 changes: 7 additions & 4 deletions plone/app/portlets/portlets/navigation_recurse.pt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
bottomLevel options/bottomLevel | nothing;
supress_icon view/data/no_icons;
supress_thumb view/data/no_thumbs;
thumb_scale view/thumb_scale"
thumb_scale view/thumb_scale;
icons nocall:context/@@iconresolver;"
i18n:domain="plone">

<metal:main define-macro="nav_main"
Expand Down Expand Up @@ -35,9 +36,11 @@
title node/Description;
class string:${item_class}${li_class}${li_extr_class}${li_folder_class} ${item_type_class}">

<img class="mime-icon" tal:condition="python:item_type =='File' and not supress_icon"
tal:attributes="href node/getURL;
src python:view.getMimeTypeIcon(node);">
<tal:icon tal:condition="python: not supress_icon and item_type != 'File'"
tal:replace="structure python:icons.tag(f'contenttype/{normalizeString(item_type)}')" />

<tal:icon tal:condition="python: not supress_icon and item_type == 'File'"
tal:replace="structure python:icons.tag(f'mimetype-{item.mime_type}')" />

<img tal:condition="python:has_thumb and thumb_scale"
tal:replace="structure python:image_scale.tag(item, 'image', scale=thumb_scale, css_class='float-end thumb-'+thumb_scale)">
Expand Down

0 comments on commit d7fe54d

Please sign in to comment.