3

I have to look up the Publication Type in a GUI extension (T2011 SP1) to make the extension (context menu extension) only available for a specific Publication type (e.g. 'Web').

The extension has been set up and is working correctly, but now the extension is available for all Publication Types.

This is what I have so far:

Extensions.ConfigurationManager.prototype.isAvailable = function ConfigurationManager$isAvailable(selection) {               
    //add logic to catch publication type
    var itemID = selection.getItem(0);
    var typeOfSelection = $models.getItemType(itemID);

    if (typeOfSelection == $const.ItemType.STRUCTURE_GROUP || 
        typeOfSelection == $const.ItemType.PAGE) {
        return true;
    }
    else {
        return false; 
    }
}

2 Answers 2

5

The isAvailable() method (and isEnabled() for that matter too) is a synchronous method, as it needs to return a value.

Now you would be able to use the following to check the Publication Type:

var isWebType = true;
var pub = $models.getItem(selection.getItem(0)).getPublication();
if (pub) {
    var pubType = pub.getPublicationType();
    if (pubType) {
       isWebType = pubType == "Web";
    }
}
return isWebType;

Were it not that the method getPublicationType() only works on a fully loaded Publication object, and loading items in the UI framework is an asynchronous action.

As discussed in this question already, I don't think there is a way to wait for the loading of an item in this method (besides the fact that it would make this a very heavy method which you probably also don't want).

So my suggestion would be to simply return true from isAvailable() when it comes to the Publication Type (you can use my sample code and place it in there, if the Publication by any chance is loaded, then you will have access to its Publication Type and the code will do a correct check) and handle any exceptions in the execute() call when you will have the time to load the Publication to get its correct Publication Type.

6

Indeed, as Bart explained, the point is that you won't have enough information when it came to isAvailable/isEnabled.

Information for the item, could be collected from List Item Properties(when list gets loaded, it contains simple item representation), or from Item properties (when you load an item, it has full set of properties associated with item).

In your case the PublicationType not contained a part of list properties. So even if you have list loaded, you still need to load an Item to collect this property.

I would suggest following actions to achieve functionality you need:

  1. Create data extender to add a property, based on which you'll be able to properly update a context menu command state.

  2. Add ItemType extension, which will extend Tridion.ContentManager.Publication to be able to collect a property from either publication or list node.

  3. Use this property to determine a command state.


Update:

I have just checked, Publication List node already contains PublicationType in Publication node.

This makes it a little bit simpler.

You can do the following trick:

if (selection.getItemType(0) == $const.ItemType.PUBLICATION)
{
    var itemId = selection.getItem(0);
    var item = $models.getItem(itemId);

    var publicationType = item.getPublicationType();

    // If publication Type is not defined, then try to find it from lists loaded
    if (!publicationType)
    {

        // Loop over already loaded lists, and try to find a list node there.
        for (var i = 0, lists = $models.getListsRegistry(), list; list = $models.getItem(lists[i]); i++)
        {
            // you only need navigation lists
            if (Tridion.OO.implementsInterface(list, "Tridion.ContentManager.ListNavigation")/* && list.hasItem(itemId)*/)
            {
                publicationType = $xml.getInnerText(list.getXmlDocument(), "/tcm:*/tcm:Item[@ID=\"{0}\"]/@PublicationType".format(itemId));
                if (publicationType)
                {
                    break;
                }
            }
        }
    }

    if (publicationType == "0")
    {
        return true;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.