portal_actions reference
Overview
The portal_actions tool
is an object in the root directory of all Plone sites that provides
access to the various actions in the site. An action usually
manifests itself as link or a menu-item somewhere in the site.
For example, the tabs along the top of the Plone site ('Home',
'Products', etc..) are actions that are defined in the portal_actions
tool.
Class
ActionsTool
API Docs
http://api.plone.org/Plone/2.1.1/public/CMFCore.ActionsTool.ActionsTool-class.html for the API docs of this class.
Usage examples:
Obtain actions available to current user:
from Products.CMFCore.utils import getToolByName
actions = getToolByName(context, 'portal_actions').listFilteredActions()
In the above example actions would contain a dictionary of lists of
dictionaries representing the actions available to the current
user. E.g.:
{'site_actions':
[
{'category': 'site_actions',
'available': True,
'title': 'Small Text',
'url': <bound method ActionInfo._getURL of {...}>,
'name': 'Small Text',
'visible': True,
'allowed': True,
'id': 'small_text',
'permissions': ('View',)
},
{'category': 'site_actions',
'available': True,
'title': 'Normal Text',
'url': <bound method ActionInfo._getURL of {...}>,
'name': 'Normal Text',
'visible': True,
'allowed': True,
'id': 'normal_text',
'permissions': ('View',)
},
...
],
...
'portal_tabs':
[
{
'category': 'portal_tabs',
'available': True,
'title': 'Home',
'url': <bound method ActionInfo._getURL of {...}>,
'name': 'Home',
'visible': True,
'allowed': True,
'id': 'index_html',
'permissions': ('View',)
},
...
],
...
}
And given this example, it is trivial to obtain a list of actions in a particular category.
Obtain a list of the actions in a particular category:
from Products.CMFCore.utils import getToolByName
portal_tabs = getToolByName(context, 'portal_actions').listFilteredActions()['portal_tabs']
In the above snippet, portal_tabs would contain a list of
dictionaries representing all of the actions with category
'portal_tabs'. E.g.:
[
{
'category': 'portal_tabs',
'available': True,
'title': 'Home',
'url': <bound method ActionInfo._getURL of {...}>,
'name': 'Home',
'visible': True,
'allowed': True,
'id': 'index_html',
'permissions': ('View',)
},
{
'category': 'portal_tabs',
'available': True,
'title': 'Products',
'url': <bound method ActionInfo._getURL of {...}>,
'name': 'Home',
'visible': True,
'allowed': True,
'id': 'products',
'permissions': ('View',)
},
...
],
Iterating through actions in a TAL template:
<ul>
<tal:actions repeat="action python:context.portal_actions.listFilteredActionsFor(context)['portal_tabs']">
<li>
<a tal:attributes="href action/url; title action/title;" tal:content="action/title">
Action title
</a>
</li>
</tal:actions>
</ul>
The above snippet creates an unordered list of links for the actions with category portal_tabs. Its output would be something like:
- Home
- Products
- About
- ...
Where each item is linked to its associated URL.

Author: