4

This is question gets asked repeatedly in the Alfresco JIRA, in forums and on the Alfresco IRC so I thought I would ask and answer it here as this is the most likely place that people will find the solution, the question is this...

I've created a customization to the Alfresco Share header following the steps described in this blog post to remove a menu item.

However, when I login to Alfresco that the customization works on everything except the search page - What am I doing wrong?

Dave Draper
  • 1,837
  • 11
  • 25

1 Answers1

6

The search page in Alfresco Share is one of the few full Aikau pages in the application. The majority of the pages in Share were written before Aikau was created and are comprised of multiple Surf Components - of which the header has been rendered by Aikau since version 4.2.

The search page was updated in 5.0 to be a full Aikau page and does not use the same Surf Component to render the header.

This means that the standard header customization will only be targeting the Surf Component WebScript and not the full page WebScript.

To get this to work you need to take advantage of the alwaysApply element in the module configuration.

So for example a typical extension module to target the header might look like this:

<extension>
  <modules>
    <module>
      <id>Extension Module</id>
      <auto-deploy>true</auto-deploy>
      <evaluator type="default.extensibility.evaluator"/>
        <customizations>   
          <customization>
            <targetPackageRoot>org.alfresco</targetPackageRoot>
            <sourcePackageRoot>org.alfresco.share.pages.customizations</sourcePackageRoot>
          </customization>
        </customizations>
      </evaluator>
    </module>
  </modules>
</extension>

This would be targeting all WebScripts in the org.alfresco package and would look for matching files in the org.alfresco.share.pages.customizations package.

So the Share header is defined by the share-header.get.js WebScript, and if your extension file should be in org.alfresco.share.pages.customizations.share-header.get.js.

However, the org.alfresco.share-header.get.js WebScript is not used on the search page, which is why the customization will not take effect.

Instead, you should include an additional customization block to ensure your extension is applied, it should look similar to this:

<customization>    
  <targetPackageRoot>org.alfresco.share.pages</targetPackageRoot>
  <sourcePackageRoot>org.alfresco.share.pages.customizations.share.header</sourcePackageRoot>
  <alwaysApply>
    <webscript>share-header</webscript>
  </alwaysApply>
</customization>

This says that for all WebScripts in the org.alfresco.share.pages package (which is where all full Aikau pages are defined). You should always apply extension files called "share-header" (so .get.js, .get.html.ftl and .get.properties files would also be matched).

Note that the sourcePackageRoot is defines exactly where the extension file should be found.

Dave Draper
  • 1,837
  • 11
  • 25
  • The share-header alwaysApply example had a nasty issue for me. Naive as I was, I expected HEADER_APP_MENU_BAR to be there. Might be true most of he time. Not for custom-model-manager, manage-site-members, manage-sites in admin-console where I blew it. Seems quite tricky to get it right tweaking the menubar everywhere. – Andreas Steffan Nov 10 '16 at 16:47
  • I don't quite understand why it would be a problem because the HEADER_APP_MENU_BAR is always in the header model, which is either rendered as one of many Surf Components in the older style Share page, or within the single Surf Component on an Aikau page. The admin console pages for site management and CMM dodn't import the header lib so won't include a widget with that id, but it will still be on the page in the standard header component. You should always code defensively to check that the widgetUtils function actually returns a value - all my examples of extending Share do this. – Dave Draper Nov 10 '16 at 19:57
  • The problem is that when using this snippet, HEADER_APP_MENU_BAR is not always there (e.g. CMM and SM pages) and hence, you need quite a bit of convoluted code to get a basic requirement "change menu everywhere(!)" right. Wonder how long it takes an average developer to get there. – Andreas Steffan Nov 10 '16 at 21:21