You are on page 1of 3

Custom Metdata in Alfresco Share

I recently setup Alfresco 3.0 Community for internal usage. I was able to get everything running with LDAP and NTLM integration. The Share application however, needed some tweaking as I had added some custom types and Share does not display custom metadata as of 3.0. So instead for going for the 3.1 Preview, which has forms support I decided to stick to the more stable 3.0 and tweak it. In this post I will describe the changes required. I recently setup Alfresco 3.1 Community for internal usage. I was able to get everything running with LDAP and NTLM integration. The Share application however, needed some tweaking as I had added some custom types and Share does not display custom metadata as of 3.1. So instead for going for the 3.2 Preview, which has forms support I decided to stick to the more stable 3.0 and tweak it. In this post I will describe the changes required. Please note that this post applies only to Alfresco 3.1 Community. Alfresco 3.2 adds forms support which provides support for any custom metadata to be displayed/edited with very minimal configuration. First you need to tell the Web Framework to show your custom type by adding the following in web-framework-config-custom.xml in the web-extension folder.
<config evaluator=string -compare condition=my:customtype> <form> <field-visibility> <show id=my:prop1? /> <show id=my:prop2? /> </field-visibility> <appearance> <field id=my:prop1? /> <field id=my:prop2? /> </appearance> </form> </config>

Now edit share/WEB-INF/classes/alfresco/sitewebscripts/org/alfresco/components/document-details/document-info.get.html.ftl and add appropriate HTML for displaying the custom metadata as below
<div class=info -section id=${args.htmlid} -customtype> <div class=heading>Custom Metadata</div> <div class=info> <span class=meta -label>Prop1:</span> <span id=${args.htmlid} -prop1? class=meta -value></span> </div> <div class=info> <span class=meta -label>Prop2:</span> <span id=${args.htmlid} -prop2? class=meta -value></span> </div> </div> </div>

Next, modify share/components/document-details/document-info.js to display the additional metdata. This needs to be done in the onDocumentDetailsAvailable function as follows
if (!docData.customtype) { var customTypeDiv = Dom.get(this.id + -customtype); customTypeDiv.innerHTML = ; } else { Dom.get(this.id + -prop1?).innerHTML = $html(docData.customtype.prop1); Dom.get(this.id + -prop2?).innerHTML = $html(docData.customtype.prop2); }

We have now made the changes in Share to display the custom metadata. But the data will still not be displayed because Share gets the data from a Web Script which also needs to be modified. To do that modify the file alfresco/WEBINF/classes/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/docli st.get.js as follows Add the following lines inside the <#assign tags> block.
<#if item.customtype?exists> customtype: { prop1 : ${item.customtype.prop1}, prop2 : ${item.customtype.prop2} },

Now modify the alfresco/WEBINF/classes/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/docli st.get.js file and add the following just before the items.push() line
var customtype = null; if (assetType == document && asset.type == {myuri}customtype) { var prop1 = ; if (asset. properties["{myuri}prop1"]) { prop1 = asset.properties["{myuri}prop1"]; } var prop2 = ; if (asset.properties["{myuri}prop2"]) { prop2 = asset.properties["{myuri}prop2"]; } customtype = { prop1:prop1, prop2: prop2

} }

This should display the custom metdata in Share when you click on a document and go to the detail page. In next post I will cover how you can display the metdata in the Edit Metadata screen and also save any changes.

You might also like