Friday, April 15, 2011

Hide Site Actions menu item in Sharepoint 2010

Today I've decided to make an exercise for my fingers and write one more post, although I haven't done it for quite long already.

The topic is related to SharePoint 2010. This is a very known problem on hiding View All Site Content link, which comes all the way from previous MOSS version. There it could be solved using some basic javascript or css change. With 2010 version the pain was added in the form of presenting this link in Site Actions menu. The same JavaScript won't work as expected in that case, because the ID generated for that menu item in drop-down menu seems to be quite dynamic (zzX prefix added, where X might be any number).

So my approach is to refactor our JavaScript code to something similar to this one.

<script language="javascript">
String.prototype.endsWith = function(str)
{return (this.match(str+"$")==str)}

document.getElementById('ctl00_PlaceHolderLeftNavBar_PlaceHolderQuickLaunchBottom_PlaceHolderQuickLaunchBottomV4_idNavLinkViewAllV4').style.visibility = "hidden";

var menuItems = document.getElementsByTagName("ie:menuitem");
for (var key in menuItems)
 if (key.endsWith("ViewAllSiteContents"))
  menuItems[key].hidden = true;

I also wanna mention some caveat on that whole Site Actions menu items stuff. Although you can hide some of the items there using <HideCustomAction> declarations within feature's elements, this approach won't work with View All Site Content menu item. I was pulling my hair out trying to find the declaration for it somewhere, and after all I was surprised to see it in <ConsoleNode> declaration for EditingMenu. As far as there is no way of hiding console nodes declaratively, you will need to write feature receiver which will get the .xml file with declaration, change it, check-in and approve. And even in this case this is not the best solution, as far as this EditingMenu is a "site collection scoped" functionality, so there is no way of applying this only to some specific subsites.

Hope I gave a very thourough insight into that topic, if something is missing or needs to be pointed to, don't hesitate to ask.

No comments: