Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.

 

HXH
HXH
May 1, 2012
  5723
(0 votes)

EPiServer Workflow Replacement : Step 6 - Hooking the Ready to Publish Event

This is the last in a series of posts about how my company built a replacement workflow platform for EPiServer. Why we chose to do this is explained here: http://world.episerver.com/Blogs/Hans/Dates/2012/4/EPiServer-Workflow-Replacement--Step-1Explanation-and-Disabling-Edit-Tab/

I’ve covered why we had to build our own workflow. I’ve gone into how to disable the base Workflow tab and replace it with your own GuiPlugin named Workflow. I’ve explained from the top down how this all works from a user/admin perspective, I’ve shown what database fields need to be updated to reject pages – and I’ve given you a workaround to disable that pesky Save and Publish button.

The only other critical component to this entire process is the ability  to notify approvers whenever a page is marked “Ready to Publish”. To do this, we create a new class and hook into the DataFactory.Instance.CheckingInPage event like so:

First – I create a new class : I named mine CustomPageActionControl.cs. I then designate it as a [PagePlugIn] and set up the Initialize method..this is where we hook CheckingInPage – in this instance by calling an additional class called NotifyApprovers.

    [PagePlugIn]
    public class CustomPageActionControl
    {
        public static void Initialize(int bitflags)
        {
            DataFactory.Instance.CheckingInPage += NotifyApprovers;
        }
    }
 

(As a side note, this is really handy for doing all sorts of other things..most of our sites also hook DataFactory.Instance.SavedPage, PublishedPage, DeletingPage, MovingPage, etc – there are all sorts of things you can hook into: http://sdk.episerver.com/library/cms5/html/AllMembers_T_EPiServer_DataFactory.htm )

 

Anyway..our NotifyApprovers method performs thusly:

  1. We get a working version of the page information that we want to send on – PageVersionURL, Approver User Names, etc..
  2. We iterate through an array of all access control entities, check their roles (in this instance they have to have LANGUAGE_EN-US or the correct locale access – so we don’t send our European users information about approving US Locale specific information) and getting a list of all users who can approve
  3. We email out all approvers with information about the page (as seen in step #3)

 

The below should be cleaned up and made more DRY (i.e. take advantage of LINQ), but you get the idea..

 

 private static void NotifyApprovers(object sender, PageEventArgs e)
        {
            String ApproverUserNames = "";
            List<String> EmailList = new List<String>();
            String PageVersionUrl = ConfigurationManager.AppSettings["BaseUrl"] + e.Page.LinkURL;
            PageVersionUrl = PageVersionUrl.Replace("&epslanguage", "_" + e.Page.WorkPageID + "&idkeep=True&epslanguage");

            foreach (EPiServer.Security.RawACE Ace in e.Page.ACL.ToRawACEArray()) // Get array of all access control entries
            {
                EPiServer.Security.AccessControlEntry EAC = new EPiServer.Security.AccessControlEntry(Ace);
                if ((Ace.Access & EPiServer.Security.AccessLevel.Publish) == EPiServer.Security.AccessLevel.Publish) //Only look at users who have access to publish page
                {
                    foreach (System.Web.Security.MembershipUser AllUsers in Membership.GetAllUsers())
                    {
                        if (Roles.IsUserInRole(AllUsers.UserName, "LANGUAGE_" + (Convert.ToString(e.Page.LanguageID)).ToUpper())) // User has locale access
                        {
                            if (Roles.IsUserInRole(AllUsers.UserName, Ace.Name))
                            { //user has publish access for this page
                                if (!EmailList.Contains(AllUsers.Email.ToString())) //only add users once
                                {
                                    ApproverUserNames += UserProfileTools.GetFullName(AllUsers.UserName.ToString()) + "; ";
                                    EmailList.Add(AllUsers.Email.ToString());
                                }
                            }
                        }
                    }

                }
            }

            String EmailBody = "<h2>EPiServer Approval Requested: Page Ready to Publish</h2><table style=\"font-family: Arial; font-size: 12px; \"><tr><td><b>Title:</b></td><td>" + e.Page.PageName + "</td></tr><tr><td><b>Submitter:</b></td><td>" + UserProfileTools.GetFullName(e.Page.ChangedBy) + "</td></tr><tr><td><b>Version URL:</b></td><td>" + PageVersionUrl + "</td></tr><tr><td><b>Published URL:</b></td><td>" + ConfigurationManager.AppSettings["BaseUrl"] + e.Page.LinkURL + "</td></tr><tr><td><b>Necessary Action:</b></td><td>This page is ready for your approval. Please log into EPiServer and visit the <i>Ready to Publish URL</i> specified above. For your reference, the current published page version is also available by visiting the <i>Published Version URL</i>." + "</td></tr><tr><td><b>Content Approvers:</b></td><td>" + ApproverUserNames + "</td></tr></table>";
            if (EmailList.Count() > 0)
               EmailTools.SendTemplatedEmail("EPiServer Page Approval Request – www.mysite.com", EmailBody, EmailList, "EPiServer@episerver.com", "EPiServer");

        }

 

And that’s it! When an editor hits “Ready to Publish”, all of the approvers are automatically notified that they need to go in and check out the content.

That sums up our custom workflow application. If you found it at all useful in any respect (or if you feel like pointing out my errors in logic and/or code) I’d love to hear from you in the comments below.

May 01, 2012

Comments

Aug 22, 2017 09:20 PM

17track.net

misor aliya
misor aliya Jun 1, 2018 10:15 AM

https://www.zillows.xyz/

nick010
nick010 Jul 11, 2018 09:16 PM

Jawaharlal Nehru Technological University, Kakinada is a public university, in Kakinada, East Godavari district, north of the Indian state of Andhra Pradesh. It is one of India's leading universities focusing on engineering for more JNTUK

Please login to comment.
Latest blogs
Optimizely Content Graph on mobile application

CG everywhere! I pull schema from our default index https://cg.optimizely.com/app/graphiql?auth=eBrGunULiC5TziTCtiOLEmov2LijBf30obh0KmhcBlyTktGZ in...

Cuong Nguyen Dinh | Jan 20, 2025

Image Analyzer with AI Assistant for Optimizely

The Smart Image Analyzer is a new feature in the Epicweb AI Assistant for Optimizely CMS that automates the management of image metadata, such as...

Luc Gosso (MVP) | Jan 16, 2025 | Syndicated blog

How to: create Decimal metafield with custom precision

If you are using catalog system, the way of creating metafields are easy – in fact, you can forget about “metafields”, all you should be using is t...

Quan Mai | Jan 16, 2025 | Syndicated blog

Level Up with Optimizely's Newly Relaunched Certifications!

We're thrilled to announce the relaunch of our Optimizely Certifications—designed to help partners, customers, and developers redefine what it mean...

Satata Satez | Jan 14, 2025