Alfresco: extending Aikau widgets without “id”

One of the most used mechanisms to extend Aikau pages is to find a page widget with widgetUtils.findObject function and to inject new services and new widgets in order to build an extended Aikau page.

// Find widget by id
var siteConfig = widgetUtils.findObject(model.jsonModel, "id", "HEADER_SITE_CONFIGURATION_DROPDOWN");

if (siteConfig != null) {
    
    // Inject new service    
    model.jsonModel.services.push("sitehomepage/SiteHomePageService");
        
    // Inject new widgets at "HEADER_SITE_CONFIGURATION_DROPDOWN"
    siteConfig.config.widgets.push({
        //...
    }
}

However, what about if our targeted widget has no ID field?

I was extending Manage Sites aikau page (manage-sites.get.js) to add a new option (Restore Home Page) for every Site at actions column.

alfresco-sites-manager-extension

However, there is no ID to find on this widgets at Alfresco source code.

name: "alfresco/documentlibrary/views/layouts/Cell",
config: {
   additionalCssClasses: "actions smallpad",
   widgets: [
      {
         name: "alfresco/menus/AlfMenuBar",
         align: "left",
         config: {
            widgets: [
               {
                  name: "alfresco/menus/AlfMenuBarPopup",
                  config: {
                     label: msg.get("message.actions-header-label"),
                     widgets: [
                        {
                           name: "alfresco/menus/AlfMenuGroup",
                           config: {
                              additionalCssClasses: "unmargined",
                              widgets: [
                              ...

So, I’ve been learning about widgetUtils.findObject behavior at spring surf script class ScriptSiteData.java and I’ve found that in fact it can be used to find by every object field. In my case there is just one AlfMenuGroup, so I’ve extended this page by using following approach.

// Find widget by NAME (!)
var dropDownMenuConfig = widgetUtils.findObject(model.jsonModel, "name", "alfresco/menus/AlfMenuGroup");

if (dropDownMenuConfig != null) {
	
    model.jsonModel.services.push("sitehomepage/RestoreSiteHomePageService");
	
	dropDownMenuConfig.config.widgets.push({
        name: "alfresco/menus/AlfMenuItem",
        config: {
           label: msg.get("button.site.home.page.restore"),
           iconClass: "alf-fullscreen-icon",
           publishTopic: "ALF_RESTORE_SITE_HOME_PAGE",
           publishPayloadType: "BUILD",
           publishPayload: {
              site: {
                 alfType: "item",
                 alfProperty: "shortName"
              }
           }
        }
    });
}

Obviously this is not the cleaner way to solve this problem, but it can help in the meanwhile.

Remember that all this code is available as an Alfresco SDK 2.1 project at https://github.com/angelborroy/alfresco-site-home-page

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s