Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you configure an SDL Tridion CME extension for a subset of views?

I have created a new editor for SDL Tridion which adds some new functionality to the ribbon bar. This is enabled by adding the following snippet to the editor.config

    <!-- ItemCommenting PowerTool -->
    <ext:extension assignid="ItemCommenting" name="Save and&lt;br/&gt;Comment" pageid="HomePage" groupid="ManageGroup" insertbefore="SaveCloseBtn">
      <ext:command>PT_ItemCommenting</ext:command>
      <ext:title>Save and Comment</ext:title>
      <ext:issmallbutton>false</ext:issmallbutton>
      <ext:dependencies>
        <cfg:dependency>PowerTools.Commands</cfg:dependency>
      </ext:dependencies>
      <ext:apply>
        <ext:view name="*" />
      </ext:apply>
    </ext:extension>

This is applied to all views by using a wildcard value in the node. This has results in my new button being added to the ribbon of every view, including the main dashboard. Is there a way to add this to all views except for the dashboard? Or do I have to create something like this?

    <ext:apply>
        <ext:view name="PageView" />
        <ext:view name="ComponentView" />
        <ext:view name="SchemaView" />
    </ext:apply>

If this is the only way to achieve the result I need, is there a list of all the view names somewhere?

like image 540
Chris Summers Avatar asked Oct 18 '12 21:10

Chris Summers


2 Answers

Workaround provided by Jaime will not gonna work, because:

  • Ribbon Toolbar will hide buttons only on the Create tab if isAvailable method of the corresponding command will return false.
  • Most of the buttons in RibbonToolbar implements specific Tridion.Controls.RibbonButton interface. This means, when you'll try to get Tridion.Controls.Button control for the same element - you'll get totally different control, based on the same html element. So RibbonToolbar will not know about it and it will work incorrectly.
  • If you want to hide button in RibbonToolbar, you should use public methods on RibbonToolbar and RibbonPage instead. Thus it will be correctly handled by RibbonToolbar. Example:
var toolbar = $controls.getControl($("#ItemToolbar"), "Tridion.Controls.RibbonToolbar");
var page = toolbar.getPageById("HomePage");
page.hideItem(buttonId);
page.showItem(buttonId);

As for the original question, here is pretty simple and easiest solution:

<ext:add>
    <ext:extension assignid="ItemCommenting" name="Save and&lt;br/&gt;Comment" pageid="HomePage" groupid="ManageGroup" insertbefore="SaveCloseBtn">
        <ext:command>PT_ItemCommenting</ext:command>
        <ext:title>Save and Comment</ext:title>
        <ext:issmallbutton>false</ext:issmallbutton>
        <ext:dependencies>
            <cfg:dependency>PowerTools.Commands</cfg:dependency>
        </ext:dependencies>
        <ext:apply>
            <ext:view name="*" />
        </ext:apply>
    </ext:extension>
</ext:add>
<ext:remove>
    <ext:extension id="ItemCommenting">
        <ext:apply>
            <ext:view name="DashboardView" />
        </ext:apply>
    </ext:extension>
</ext:remove>
like image 121
Boris Ponomarenko Avatar answered Nov 04 '22 17:11

Boris Ponomarenko


As far as I know you need to specify all the views or use the wildcard. It will be nice that the isAvailable functionality would work for the Ribbon Tool bar buttons, right? Meaning that if the command returns false in the _isAvailable method, the button will not show...

Well, I found a work around. You can do something like this within your isAvailable method in your command:

Your.Namespace.PT_ItemCommenting.prototype._isAvailable = function PT_ItemCommenting$_isAvailable(selection) {
    var isAvailable = $display.getView().getId()!='DashboardView';
    if(isAvailable){
        return true;
    }
    var button = $controls.getControl($("#ItemCommenting"), "Tridion.Controls.Button");
    button.hide();
    return false;
};

I think this is actually a good practice, since it will "hide" the commands if they shouldn't be available, right?

Let me know how it works out.

like image 44
Jaime Santos Alcón Avatar answered Nov 04 '22 17:11

Jaime Santos Alcón