From a88f4b18375150266e12e012e356c9996a2c2ef5 Mon Sep 17 00:00:00 2001 From: Peter Holzer Date: Thu, 7 Apr 2022 19:20:44 +0200 Subject: [PATCH 1/2] Added support for images in liveSearch results. --- Products/CMFPlone/browser/search.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Products/CMFPlone/browser/search.py b/Products/CMFPlone/browser/search.py index a8c34129d6..8e396ed2ed 100644 --- a/Products/CMFPlone/browser/search.py +++ b/Products/CMFPlone/browser/search.py @@ -1,5 +1,6 @@ from DateTime import DateTime from plone.app.contentlisting.interfaces import IContentListing +from plone.app.layout.navigation.interfaces import INavigationRoot from plone.registry.interfaces import IRegistry from Products.CMFCore.utils import getToolByName from Products.CMFPlone.browser.navtree import getNavigationRoot @@ -249,27 +250,37 @@ def __call__(self): registry = queryUtility(IRegistry) length = registry.get('plone.search_results_description_length') + show_images = registry.get('plone.search_show_images') + if show_images: + image_scale = registry.get('plone.search_image_scale') + # image_scaling = getMultiAdapter((self.context, self.request), name='image_scale') + self.image_scaling = getMultiAdapter((INavigationRoot(self.context), self.request), name='image_scale') plone_view = getMultiAdapter( (self.context, self.request), name='plone') - registry = getUtility(IRegistry) view_action_types = registry.get( 'plone.types_use_view_action_in_listings', []) for item in batch: url = item.getURL() if item.portal_type in view_action_types: url = '%s/view' % url + img_tag = None + if show_images: + img_tag = self.get_image_tag(item, image_scale) items.append({ 'id': item.UID, 'title': item.Title, 'description': plone_view.cropText(item.Description, length), 'url': url, 'state': item.review_state if item.review_state else None, + 'img_tag': img_tag, }) return json.dumps({ 'total': len(results), 'items': items }) + def get_image_tag(self, item, image_scale): + return self.image_scaling.tag(item, "image", scale=image_scale) class SortOption: From f9034a5751143996eb8b67e1f7ac52be6e68fc0b Mon Sep 17 00:00:00 2001 From: Peter Holzer Date: Thu, 7 Apr 2022 19:44:33 +0200 Subject: [PATCH 2/2] add news --- news/3489.feature | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 news/3489.feature diff --git a/news/3489.feature b/news/3489.feature new file mode 100644 index 0000000000..4b029fb1f5 --- /dev/null +++ b/news/3489.feature @@ -0,0 +1,2 @@ +Added support for images in liveSearch results. +[agitator] \ No newline at end of file