Goal of this post
The goal of this post is to guide you through the different steps for replacing the ‘Submit for Approval’ quick access button in a WCM environment.
Problematic overview
‘Submit for Approval’ is a native button which aims at firing a ‘Parallel Approval’ workflow when Publishing features are activated in a WCM web site:

When deploying a custom approval workflow, you’ll probably need to overwrite the logic of this button to start your custom workflow correctly.
You would also be able to customize the icon and the text of your custom button to achieve something like this:

Write a custom class CustomSubmitForApproval
1. Set pre-requisites:
-
First, add those tworeferences : Microsoft.SharePoint, Microsoft.SharePoint.Publishing
-
Create a public sealed class that inherits from:
Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.ConsoleAction
-
Add a constant used as argument of post back events:
private const string PostBackEventArg = "submitForApproval";
2. Add a constructor and customize your custom quick access button:
public CustomSubmitForApprovalButton()
: base()
{
this.DisplayText = "Custom Submit for Approval";
this.ImageUrl = "/_layouts/images/workflows.gif";
}
3. Override NavigateUrl property and fire post back events:public override string NavigateUrl
{
get
{
return String.Format("javascript:{0}", Page.ClientScript.GetPostBackEventReference(
this, CustomSubmitForApprovalButton.PostBackEventArg));
}
}
4. Override RaisePostBackEvent method, and implement your redirection logic
In our case, we force the page check in and we redirect toward check-in page:
public override void RaisePostBackEvent(string eventArgument)
{
try
{
if (eventArgument == CustomSubmitForApprovalButton.PostBackEventArg)
{
SPFile myFile = SPContext.Current.File;
// Auto checkin page before redirecting to 'Publish Major Version'
if (myFile.CheckOutStatus != SPFile.SPCheckOutStatus.None)
{
myFile.CheckIn("Default comment", SPCheckinType.MinorCheckIn);
}
string redirectUrl = String.Format(
"{0}_layouts/Checkin.aspx?FileName={1}&Publish=true&List={2}&Source={3}",
SPContext.Current.Web.ServerRelativeUrl,
SPContext.Current.ListItemServerRelativeUrl,
Convert.ToString(SPContext.Current.List.ID),
Page.Request.Url.OriginalString);
SPUtility.Redirect(redirectUrl, SPRedirectFlags.Default, HttpContext.Current);
}
}
catch (Exception ex)
{
ShowError(ex, new ConsoleError(ex.Message));
}
}
You can override some properties to control what is the minimum level of permission required to access the feature, and what are the states causing your button to appear in the page editing toolbar. In samples below, users have to be granted the permission of adding items and page has to be a publishing page waiting for approval.
5. Override SPBasePermissions UserRights property
public override SPBasePermissions UserRights
{
get { return SPBasePermissions.AddListItems; }
}
6. Override AuthoringStates RequiredStates property
public override AuthoringStates RequiredStates
{
get
{
return AuthoringStates.IsPublishingPageTrue |
AuthoringStates.SaveConflictExistsFalse |
AuthoringStates.IsMajorVersionFalse |
AuthoringStates.IsApprovalWorkflowConfiguredTrue |
AuthoringStates.InEditModeFalse |
AuthoringStates.IsApprovalWorkflowRunningFalse;
}
}
Overwrite CustomQuickAccess.xml file in master pages gallery
When your custom class is compiled and deployed on your SharePoint server, you will have to overwrite CustomQuickAccess.xml located into MOSS master pages gallery.
In a live scenario, we recommend to deploy this file through activation event of a custom feature. Simply make sure not to override an already existing file.
In our sample scenario, we are going to edit this file directly from SharePoint Designer :
1. Open CustomQuickAccess.xml from /_catalogs/masterpage/Editing Menu
2. Add a reference to our custom class (mind to adjust assembly reference with your own assembly qualified name):
<references>
<reference TagPrefix="Prexens"
assembly="Prexens.SharePoint.CustomQuickAccessButton,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5"
namespace="Prexens.SharePoint.CustomQuickAccessButton" />
</references>
3. Add a ConsoleNode that override native qaPublish Node ID:
<structure>
<ConsoleNode
Sequence="65"
ConfigMenu="Replace"
Action="Prexens:CustomSubmitForApprovalButton"
ID="CustomQuickAccessButton_SubmitForApproval"
ChangedNodeID="qaPublish" />
</structure>
4. Add two ConsoleNode that remove native Approve and Decline buttons (those two feature should probably be inconsistent with your custom publishing workflow):
<ConsoleNode ConfigMenu="Delete" ChangedNodeID="qaWorkflowDecline" />
<ConsoleNode ConfigMenu="Delete" ChangedNodeID="qaWorkflowApprove" />
5. Save, publish, and approve this file in master pages gallery