diff --git a/CHANGES.rst b/CHANGES.rst index 5cace04..b961cc5 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -10,7 +10,9 @@ Breaking changes: New features: -- *add item here* +- provide Mimetype icon path for file types in contentlisting object + https://github.com/plone/Products.CMFPlone/issues/1734 + [fgrcon] Bug fixes: diff --git a/README.rst b/README.rst index 19af613..c49ff4b 100644 --- a/README.rst +++ b/README.rst @@ -156,11 +156,6 @@ uuid() - point of it is to be unique. It can for example look like this `b0e80776-d41d-4f48-bf9e-7cb1aebabad5`. -getIcon() - - Icon for the object. Returns an icon object from plone.app.layout. - If printed as a string, it will produce an HTML tag for the icon. Check - plone.app.layout for more info. - getSize() - Size in bytes for example `24`. @@ -254,3 +249,7 @@ Rights() - isVisibleInNav() - Return whether this object will be visible in a navigation view. + +MimeTypeIcon(): + Return mimetype icon from mimetype registry if contenttype is + File else None. diff --git a/plone/app/contentlisting/contentlisting.py b/plone/app/contentlisting/contentlisting.py index cccee03..1230719 100644 --- a/plone/app/contentlisting/contentlisting.py +++ b/plone/app/contentlisting/contentlisting.py @@ -1,13 +1,20 @@ # -*- coding: utf-8 -*- + +from Acquisition import aq_base from plone.app.contentlisting.interfaces import IContentListing from plone.app.contentlisting.interfaces import IContentListingObject +from plone.app.layout.navigation.root import getNavigationRoot from plone.i18n.normalizer.interfaces import IIDNormalizer from plone.registry.interfaces import IRegistry +from Products.CMFCore.utils import getToolByName from Products.CMFPlone.interfaces import INavigationSchema +from Products.MimetypesRegistry.MimeTypeItem import guess_icon_path from zope.component import getUtility from zope.component import queryUtility from zope.interface import implementer +import os + @implementer(IContentListing) class ContentListing(object): @@ -141,3 +148,18 @@ def isVisibleInNav(self): return False return True + + def MimeTypeIcon(self): + mimeicon = None + navroot = getNavigationRoot(self._brain) + contenttype = aq_base( + getattr(self._brain, 'mime_type', None)) + if contenttype: + mtt = getToolByName( + self._brain, 'mimetypes_registry') + ctype = mtt.lookup(contenttype) + mimeicon = os.path.join( + navroot, + guess_icon_path(ctype[0])) + + return mimeicon diff --git a/plone/app/contentlisting/interfaces.py b/plone/app/contentlisting/interfaces.py index 7fd3bc4..3f77c29 100644 --- a/plone/app/contentlisting/interfaces.py +++ b/plone/app/contentlisting/interfaces.py @@ -86,3 +86,8 @@ def ContentTypeClass(): """The contenttype suitable as a css class name, matching Plone conventions. """ + + def MimeTypeIcon(): + """ return mimetype icon from mimetype registry if contenttype is + File else None + """