You are here: Home / What do you need? / Help and documentation / Plone Info / How to change document actions in a Plone site

How to change document actions in a Plone site

by Darrell Kingsley last modified Mar 13, 2014 12:52 PM
You can change the code in the usual viewlet way, and change the items displayed and the text/link used via the ZMI

In Plone 3.3.5, document actions are below the body copy. In order to move them back up to around the title, you need to hide the default viewlet in viewlets.xml:

 <hidden manager="plone.belowcontentbody" skinname="*">
  <viewlet name="plone.abovecontenttitle.documentactions"/>
 </hidden>

and then add it to wherever you want. In our case it's abovecontenttitle:

 <order manager="plone.abovecontenttitle" skinname="*">
  <viewlet name="plone.abovecontenttitle.documentactions"/>
 </order>

Then there's the stuff in configure.xcml

   <browser:viewlet
       name="plone.abovecontenttitle.documentactions"
       for="*"
       manager="plone.app.layout.viewlets.interfaces.IAboveContentTitle"
       layer=".interfaces.IThemeSpecific"
       class=".viewlets.DocumentActionsViewlet"
       permission="zope.Public"
       />

and that involves copying document_actions.pt into browser/templates which looks like the following (this is the version which uses icons if they exist instead of text, you can remove that for the text version if you prefer):

<div class="visualClear"><!-- --></div>
<div i18n:domain="plone"
     class="documentActions">
    <tal:docactions tal:condition="view/actions">

    <h5 class="hiddenStructure" i18n:translate="heading_document_actions">Document Actions</h5>

    <ul tal:define="normalizeString nocall: context/@@plone/normalizeString">
    <tal:actions repeat="daction view/actions">
        <li tal:attributes="id python:'document-action-' + normalizeString(daction['id'])">
            <a href="" tal:attributes="href daction/url; title daction/description"> <img tal:condition="python: daction.get('icon')" tal:attributes="src daction/icon; alt daction/title; title daction/title"/>  <tal:action tal:condition="python: not daction.get('icon')" tal:content="daction/title"  i18n:translate="">Action name</tal:action>  </a>
        </li>
    </tal:actions>

    </ul>
    </tal:docactions>

    <div tal:replace="structure provider:plone.documentactions" />

</div>

and also adding the class definition to viewlets.py

class DocumentActionsViewlet(ViewletBase):
    def update(self):
        super(DocumentActionsViewlet, self).update()

        self.context_state = getMultiAdapter((self.context, self.request),
                                             name=u'plone_context_state')
        plone_utils = getToolByName(self.context, 'plone_utils')
        self.getIconFor = plone_utils.getIconFor
        self.actions = self.context_state.actions().get('document_actions', None)
    index = ViewPageTemplateFile("templates/document_actions.pt")

 Once that's done, and the server restarted, you'll have your document actions viewlet in the right place.

To change the title of your viewlets, go to the ZMI -> portal_actions -> document_actions and edit the title there. To add icons, which with the template above means that the text inks are replaced by icons, add icons to your theme, and then reference them as follows in the Icon (Expression) field using the appropriate image filenames:

string:$portal_url/bb_generic_icon_email.png

That's it. All done. his page has more info:

http://www.uwosh.edu/ploneprojects/documentation/how-tos/how-to-change-icons-of-document-actions