1 | from Products.CMFCore.utils import getToolByName
|
---|
2 |
|
---|
3 | ACTIONICON_RAMCACHE_ID = 'actioncons'
|
---|
4 | IMG_TAG = '<img src="%s" width="%s" height="%s" alt="%s" />'
|
---|
5 |
|
---|
6 | def renderActionIcon(self, category=None, action_id=None,
|
---|
7 | base_url='', alt=''):
|
---|
8 | """Renders the action's icon"""
|
---|
9 |
|
---|
10 | if category is None or action_id is None:
|
---|
11 | return None
|
---|
12 |
|
---|
13 | aitool = getToolByName(self, 'portal_actionicons', None)
|
---|
14 | if aitool is None:
|
---|
15 | return None
|
---|
16 |
|
---|
17 | cache = self.getCache(ACTIONICON_RAMCACHE_ID)
|
---|
18 | # compute the cache index
|
---|
19 | index = (action_id, category, base_url, alt)
|
---|
20 |
|
---|
21 | img_tag = cache.getEntry(index)
|
---|
22 | # the icon is not in the cache
|
---|
23 | if img_tag is None:
|
---|
24 | icon_path = aitool.queryActionIcon(category=category,
|
---|
25 | action_id=action_id)
|
---|
26 | if not icon_path:
|
---|
27 | return
|
---|
28 |
|
---|
29 |
|
---|
30 |
|
---|
31 | # fall back to the icon path specified in CMFActionIcons
|
---|
32 | img = self.unrestrictedTraverse(icon_path, default=None)
|
---|
33 | if img is None:
|
---|
34 | return None
|
---|
35 | img_tag = IMG_TAG % (base_url + icon_path,
|
---|
36 | getattr(img, 'width', 0),
|
---|
37 | getattr(img, 'height', 0),
|
---|
38 | alt)
|
---|
39 | if cache is not None:
|
---|
40 | cache.setEntry(index, img_tag)
|
---|
41 | return img_tag
|
---|
42 |
|
---|
43 | from Products.CPSPortlets.PortletsTool import PortletsTool
|
---|
44 | PortletsTool.renderActionIcon = renderActionIcon
|
---|