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.
- 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>
- Adding Icon for action
Copy tag-16.jpg icon from tomcat\webapps\share\components\documentlibrary\images
To tomcat\webapps\share\components\documentlibrary\actions
- 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);
- 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
- 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
2 Click on that action and you will see a form where you can add tagname which you want to add to document.
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.
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:
Martin Bergljung’s Blog
Looking for quality Alfresco Web Hosting ? Look no further than Arvixe Web Hosting !
Is possible to use javascript instead java…and retrieve input value to set tags as parameters. Bye
For which particular operation you are asking this?
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?
Could you please elaborate?
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.
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.
Hello,
Please how can I move “document-change-type” action to the “document-browse” action group. By doing this i want to let the user to change the type of a content in the “detailed view”.
Thanks
You need to override action group config which is defined in share-documentlibrary-config.xml through your share-config-custom.xml
Something like this. This is not full config you need to add rest of the details from original config. and close all tags.
Ok Thank you mitpatoliya, it worked for me.