Skip to content

Commit

Permalink
Added support for images in liveSearch results. (#3489)
Browse files Browse the repository at this point in the history
* Added support for images in liveSearch results.

* add news
  • Loading branch information
agitator authored Apr 7, 2022
1 parent 636edcc commit afd49b1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Products/CMFPlone/browser/search.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:

Expand Down
2 changes: 2 additions & 0 deletions news/3489.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Added support for images in liveSearch results.
[agitator]

0 comments on commit afd49b1

Please sign in to comment.