From 1141aa085573bab4c412f7fc9ca32316f7f1cc98 Mon Sep 17 00:00:00 2001 From: "Jens W. Klein" Date: Thu, 25 Nov 2021 15:58:18 +0100 Subject: [PATCH 1/2] improve iconsresolver for mockup usage --- Products/CMFPlone/browser/icons.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/Products/CMFPlone/browser/icons.py b/Products/CMFPlone/browser/icons.py index 1bb25e7d58..4347adef18 100644 --- a/Products/CMFPlone/browser/icons.py +++ b/Products/CMFPlone/browser/icons.py @@ -1,17 +1,11 @@ -# -*- coding: utf-8 -*- from lxml import etree from OFS.Image import File from plone.registry.interfaces import IRegistry from Products.Five.browser import BrowserView -from Products.CMFCore.interfaces import ISiteRoot from zExceptions import NotFound -from zope.component import adapter from zope.component import getUtility from zope.component.hooks import getSite from zope.interface import implementer -from zope.interface import Interface -from zope.location.interfaces import LocationError -from zope.traversing.interfaces import ITraversable from zope.publisher.interfaces import IPublishTraverse from zExceptions import NotFound @@ -58,21 +52,39 @@ def _strip_id(svgtree, cfg): SVG_MODIFER['strip_id'] = _strip_id - @implementer(IPublishTraverse) class IconsView(BrowserView): prefix = "plone.icon." defaulticon = "++plone++icons/plone.svg" - def publishTraverse(self, request, name): - self.name = name + def publishTraverse(self, request, part): + """Subpath detection + + - "@@iconsresolver/plone-copy" delivers the file. + - "@@iconsresolver/get_file/plone-copy" delivers the file too. + - "@@iconsresolver/get_url/plone-copy" delivers url to the file. + - "@@iconsresolver/get_tag/plone-copy" delivers image tag or the SVG data. + - "@@iconsresolver/get_tag/plone-copy?class=my-css-info&alt=Plone-Copy-Icon" delivers image tag or the SVG data. + """ + breakpoint() + variety = getattr(self, "variety", None) + if variety is None and part in ["get_tag", 'get_url', 'get_file']: + self.variety = part + return self + if variety is None: + self.variety = "get_file" + self.name = part return self def __call__(self): name = getattr(self, "name", None) if name is None: raise NotFound("No name were given as subpath.") + if self.variety == "get_tag": + return self.tag(self.name, tag_class=self.request.get("class", ""), tag_alt=self.request.get("alt", "")) + elif self.variety == "get_url": + return self.url(self.name) fileobj = self._iconfile(self.lookup(self.name)) return fileobj(REQUEST=self.request, RESPONSE=self.request.response) From 54a981393770f67027fa8d4906d519c24b73a4d6 Mon Sep 17 00:00:00 2001 From: "Jens W. Klein" Date: Thu, 25 Nov 2021 19:27:50 +0100 Subject: [PATCH 2/2] Update Products/CMFPlone/browser/icons.py Co-authored-by: Alessandro Pisa --- Products/CMFPlone/browser/icons.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Products/CMFPlone/browser/icons.py b/Products/CMFPlone/browser/icons.py index 4347adef18..4f21e47ae1 100644 --- a/Products/CMFPlone/browser/icons.py +++ b/Products/CMFPlone/browser/icons.py @@ -67,7 +67,6 @@ def publishTraverse(self, request, part): - "@@iconsresolver/get_tag/plone-copy" delivers image tag or the SVG data. - "@@iconsresolver/get_tag/plone-copy?class=my-css-info&alt=Plone-Copy-Icon" delivers image tag or the SVG data. """ - breakpoint() variety = getattr(self, "variety", None) if variety is None and part in ["get_tag", 'get_url', 'get_file']: self.variety = part