Today we have a question from Simon who asks why his custom template doesn’t override the default one. While he does have his template at the right place in his bundle and his deployment-fragment written to extract the template at the right place, it still doesn’t work. In the end he still has the default file.
What happened is that is file has been extracted at the right place but before the default one. So his own template has been overridden by the default one. To avoid this issue, you need to add a require tag on your deployment-fragment. As Anahide said in her comment, we need the following:
But why is it org.nuxeo.ecm.webapp.base? This is actually the Bundle-SymbolicName in the MANIFEST.MF of the bundle you want to override.
So every time you’re doing something in the deployment-fragment that needs a bundle to be deployed before, you need that require tag. You can checkout another example on a previous blog about nuxeo-platform-lang and nuxeo-platform-lang-ext.
But there are many other time when you need a require tag. It doesn’t apply only to deployment-fragment. In fact it applies to every XML component. Lets say for a moment that you don’t really like the Alert tab label. You would like to call it Notifications instead. So you would need to contribute to the action extension point. The first step is to identify the id of the action you want to override. You can browse the sources with Nuxeo IDE or go directly in Nuxeo Explorer where you can see the list of contributions to the action extension point. There is one called org.nuxeo.ecm.platform.notifications.web.actions–actions. That’s exactly the one we need. The first information you have on this page is In component org.nuxeo.ecm.platform.notifications.web.actions . It’s the name of the component containing the contribution we were looking for:
<extension point="actions" target="org.nuxeo.ecm.platform.actions.ActionService"> <documentation> Contribute a new tab where a user can subscribe to notifications. </documentation> <action enabled="true" icon="/icons/file.gif" id="TAB_MY_SUBSCRIPTIONS" label="action.subscriptions.tab" link="/incl/tabs/document_subscriptions.xhtml" order="70"> <category>VIEW_ACTION_LIST</category> <filter-id>general_documents</filter-id> <filter-id>not_anonymous</filter-id> </action> <action enabled="true" icon="/icons/file.gif" id="TAB_MANAGE_SUBSCRIPTIONS" label="action.groups.subscriptions.tab" link="/incl/tabs/document_group_subscriptions.xhtml" order="80"> <category>TAB_MANAGE_sub_tab</category> <filter-id>general_documents</filter-id> <filter-id>manage_subscriptions</filter-id> </action> <action enabled="false" id="sendEmail"/> <action enabled="true" icon="/icons/mail.gif" id="sendNotificationEmail" label="action.email.document" link="send_notification_email" order="17"> <category>DOCUMENT_UPPER_ACTION</category> <filter-id>not_folder</filter-id> <filter-id>not_anonymous</filter-id> </action> </extension>
The action defining the Alert tab is the first one with the _TAB_MYSUBSCRIPTIONS id. If you want to make sure it’s the right one, take a look the URL of a page displaying the alert tab: _https://yourserver.com/nuxeo/nxpath/default/default-domain/workspaces/[email protected]_documents?tabIds=%3ATAB_MY_SUBSCRIPTIONS&conversationId=0NXMAIN_ You can see the id in the tabIds query parameter: _tabIds=%3ATAB_MYSUBSCRIPTIONS
Now that we’re sure we found the contribution we want to override, let’s get to it:
"1.0" xml version=<component name="org.nuxeo.sample.action.contrib.override"> <!-- Component name must be unique. --> <!-- The require tag contains the name of the component holding the contribution we want to override. --> <require>org.nuxeo.ecm.platform.notifications.web.actions</require> <extension point="actions" target="org.nuxeo.ecm.platform.actions.ActionService"> <documentation> Override the TAB_MY_SUBSCRIPTIONS action to change its label. </documentation> <action id="TAB_MY_SUBSCRIPTIONS" label="my.new.label" /> </extension> </component>
As you can see we only have to provide the action id and the new label. This is because the service managing this extension point knows how to merge the action contribution. Some services only overwrite the contribution. This really depends on how it was written so make sure you check out their documentation if you need to overrride a contribution.
So here’s a small recap:
- If you need to override something in a deployment-fragment, the require tag must contains the Bundle-SymbolicName in the MANIFEST.MF of the bundle containing the deployment-fragment you want to override.
- If you need to override an extension point contribution, the require tag must contain the name of the component you want to be deployed after.
That’s it for today, See ya on Monday!