Add Custom Action in Alfresco Share

In Alfresco there are various actions available on user interface through which you can manipulate contents. Those actions are very important as it helps user to manage contents easily and enable them to operate on content. We can see few actions on document listing and when we go to document details page we can see full set of available action for that content.

There is one more detail definition of action i.e. action is a piece of code that can be executed against an

Object in the repository, optionally configured by the user via one of the user interfaces

Many times customer comes up with requirement to have extra action along with out of box actions like print content or “send as email” action based on their requirement. Most actions by their nature do something and it’s likely that they will make a RESTful call back to the repository to perform their work, which may require a custom Web Script there. Here we are going to discuss how we can add new action to alfresco share interface.

There are basically three types of actions available with in alfresco share

  • Link to share page
  •  Link to webpage (URL) (pagelink)
  • Client side Actions (Execute client side javascript)

All the actions are defined in the DocLibActions config under that config there is subsection called <actions> where all actions are defined as shown above. There is one more subsection called <actionGroups> which will decide actions should be visible at what location on the UI.

Here we will add Tagging action though which user can add tag to document.

  1. Add Action configuration with in share-config-custom.xml

Action configuration goes under “actions” section of “DocLibActions” config

<action id="document-tagging" type="javascript"  icon="tag"

label="actions.document.tagging">

<param name="function">onActionFormDialog</param>

<!-- Additional parameters for onFormDialog function  -->

<param name="itemKind">action</param>

<param name="itemId">doc-tagging</param>

<param name="mode">create</param>

<param name="destination">{node.nodeRef}</param>

<param name="successMessage">message.tagging.success</param>

<param name="failureMessage">message.tagging.failure</param>

</action>

For showing it on front end adds it into two action groups as follow.

<actionGroup id="document-browse">

<action index="370" id="document-tagging" />

</actionGroup>

<actionGroup id="document-details">

<action index="400" id="document-tagging" />

</actionGroup>

Form config for action form

<!-- Document Tagging Action Form -->

<config evaluator="string-compare" condition="doc-tagging">

<forms>

<form>

<field-visibility>

<show id="tagname"/>

</field-visibility>

<appearance>

<field id="tagname" label-id="doc-tagging.field.tagname">

<control template="/org/alfresco/components/form/controls/textarea.ftl" />

</field>

</appearance>

</form>

</forms>

</config>
  1. Adding  Icon for action

Copy tag-16.jpg icon from tomcat\webapps\share\components\documentlibrary\images

To tomcat\webapps\share\components\documentlibrary\actions

  1. Implement action bean

Create a java class which extend ActionExecuterAbstractBase as follow

public class DocumentTaggingActionExecuter extends ActionExecuterAbstractBase {

 

Within that class overridden method executeImpl you need to put business logic which is related to adding tag in our case. For adding tag you can use node service or add tag POST webscript provided by alfresco.

You can get the parameter value from form as follow

String tagname = (String) action.getParameterValue(PARAM_TAG_NAME);

  1. Register Action Bean

We need to register above bean within spring for that adds entry in the context file

custom-context.xml and place it under

<bean id="doc-tagging" class="com.mycompany.cms.action.DocumentTaggingActionExecuter" parent="action-executer">

<property name="nodeService">

<ref bean="NodeService"/>

</property>

</bean>

We can inject alfresco services within new bean just like we have added node service in this case.

tomcat\shared\classes\alfresco\extension

  1.  Testing the Action

New action can be tested as follow.

1 Go to document detail page you should be able to see new action called “Add Tag” over there

New action Add Tag

New action Add Tag

2 Click on that action and you will see a form where you can add tagname which you want to add to document.

Add Tag Text box

Add Tag Action Form

3 Click ok and you will be redirected to document detail page and will be able to see new tag added along with all other tags.

Added Tag

Added Tag

Congratulation you have just created new action by this way you can add as many actions you want in your repository. Hope this will help you in your implementations.

References:

Alfresco Forums

Martin Bergljung’s Blog

Looking for quality Alfresco Web Hosting ? Look no further than Arvixe Web Hosting !

Tags: , , , , , , , , , , , | Posted under Alfresco | RSS 2.0

Author Spotlight

mitpatoliya

mitpatoliya

I love opensource technologies working with those technologies from the time I have stepped in to the Software Industry. Alfresco CMS is my area of expertise. I have worked on various complex implementations which involved integration of Alfresco with other technologies, extensively worked with JBPM workflows and Webscripts.

6 Comments on Add Custom Action in Alfresco Share

  1. marcello says:

    Is possible to use javascript instead java…and retrieve input value to set tags as parameters. Bye

  2. bhramari says:

    HI,
    our alfresco is customized.
    we are not able to see the tag’s under the tag in the navigation column of document library.
    Ideally it should display,all the tags used in the particular site but it is empty in our case.

    how to enable it?

    • mitpatoliya mitpatoliya says:

      Could you please elaborate?

      • pawan says:

        actually in my navigation menu in my document library.. the text ADD TAG is not showing…it is showing actions.document.tagging instead…so how to do internationalization here.

        • mitpatoliya mitpatoliya says:

          You need to create one message bundle and place it in alfresco installation. even you can reuse existing bundle you have placed for other customization.
          Only thing is that has to be registered by your spring context file.

Leave a Reply

Your email address will not be published. Required fields are marked *


3 × = 12

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>