Try our conversational search powered by Generative AI!

Page tree context menu event

Vote:
 

I am fairly new to EpiServer, but...  

...does anybody know if there is a way to hook up to the event that is triggered when clicking the delete button in the page tree's context menu?  (Right clicking the context and choosing delete)

What I am trying to accomplish, is to send some additional data to the delete page. Need to notify user with this additional data before deleteing the page.  

#140186
Oct 12, 2015 16:18
Vote:
 

I am trying to warn the user when deleting a page that is referenced as dynamic content by another page. Much like the ID reference already works.  

#140191
Oct 12, 2015 16:31
Vote:
 

Hello Ola

You should look into EPiServer content events. These allow you to interact with specific events for your content. Its normally best to use an EPiServer Initialisation module for this: http://jondjones.com/how-to-hook-into-the-episerver-cms-events-pipeline/. The event you should be using is DeletingContent: http://world.episerver.com/documentation/class-library/?documentId=cms/7/fe4ab4ca-7733-9d0c-ff96-e56bb77eaef6

It should be noted that you can only stop the event, not warn users.

If you wanted to warn users then you could think implementing a IValidator which will allow you to show some validation messages to the user such as "Warning: Reference by content XXX, if you delete there could be issues". This message would however be shown each time a user looked at the content not just when attempting to delete, which is probably not the right experience: http://www.david-tec.com/2012/06/EPiServer-7-Preview---IValidator-interface/

David

#140198
Oct 12, 2015 19:07
Vote:
 

I am using episerver 6 so I'm hooking up to events via the Datafactory. But the DeletingPage event does not trigger when clicking the delete button in the context menu in the tree. It triggers when deleting, as it should. That's not what I need. I need the step before. I need to hook up to the event triggered when clicking delete on the context menu. That way I want to set up the deletepage with additional infromation, to inform user that the page you are about to delete is referenced as dynamic content by another page. 

#140205
Oct 13, 2015 9:35
Vote:
 

Apologies, I didn't notice it was a 6 R2 thread. You actually have some choices in that case. Its possible to modify the EPiServer UI with your own implementation. See my previous blog on how to achieve this:

http://www.david-tec.com/2010/05/Customising-the-EPiServer-UI/

The page you need to override is /<EPIServer url>/CMS/edit/DeletePage.aspx

David

#140206
Oct 13, 2015 9:53
Vote:
 

Great thanks! The guide was really helpful. Works fine. 

I have a follow up question though. 
How do I check if a page is referenced as dynamic content by another page? When deleting a page I need to know if some other page is referencing the page and rendering it. 

#140243
Oct 14, 2015 10:02
Vote:
 

Hello Ola

Something like this will allow you to look for links on a page (psedo code below). Note this code is inspired from my post: http://www.david-tec.com/2010/04/Automatically-convert-external-links-to-the-current-site-into-internal-links/ (kind of a reverse logic to what you want to do).

private string containsInternalLinks(PageData yourCurrentPage)
{
    // Loop properties on the page looking for those that can contain links
    foreach (var property in yourCurrentPage.Property)
    {
        if (property.Value != null)
        {
            //URL to page/external address
            if (typeof(PropertyUrl) == property.GetType())
            {
                if (this.containsLink((PropertyUrl)property))
                {
                    return "Contains link to page";
                }
            }
            //XHTML string (>255)
            else if (typeof(PropertyXhtmlString) == property.GetType())
            {
                if (this.containsLink(property.Value.ToString()))
                {
                    return "Contains link to page";
                }
            }
            //Link Collection
            else if (typeof(PropertyLinkCollection) == property.GetType())
            {
                foreach (var link in ((PropertyLinkCollection)property).Links)
                {
                    string convertedUrl = string.Empty;
                    if (this.convertLink(link.Href, out convertedUrl) == false)
                        return "Contains link to page";
                }
            }
        }
    }
}

private bool containsLink(PropertyUrl urlProperty)
{
    string returnUrl = urlProperty.Value.ToString();

    try
    {
        //Inspect the contents and replace with an internal link if necessary
        if (urlProperty.Value != null && urlProperty.ReferencedPermanentLinkIds.Count > 0)
        {
	    return true;
        }
    }
    catch { }
    return false;
}

private bool containsLink(string SourceXhtml)
{
    string returnXhtml = SourceXhtml;
    try
    {
        string RegexPattern = @"<a.*?href=[""'](?<url>.*?)[""'].*?>(?<name>.*?)</a>";
        // Find URL matches
        MatchCollection matches = Regex.Matches(returnXhtml, RegexPattern, RegexOptions.IgnoreCase);
        foreach (Match m in matches)
        {
            //Inspect the href part of each link found
            string originalUrl = m.Groups["url"].Value;
            string convertedUrl;
            if (this.convertLink(originalUrl, out convertedUrl) == false)
            {
                return true;
            }
        }
    }    
    catch { }

    return false;
}

private bool convertLink(string originalUrl, out string convertedUrl)
{
    bool returnVal = false;
    UrlBuilder covertedUrlBuilder = new UrlBuilder(originalUrl);
    convertedUrl = originalUrl;
    //Only attempt to convert to an internal URL if the site host is the same and the url starts with http
    if (originalUrl.StartsWith("http") && covertedUrlBuilder.Host == EPiServer.Configuration.Settings.Instance.SiteUrl.Host)
    {
        returnVal = Global.UrlRewriteProvider.ConvertToInternal(covertedUrlBuilder);
        if (returnVal)
            convertedUrl = covertedUrlBuilder.ToString();
    }
    return returnVal;
}
#140259
Oct 14, 2015 12:28
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.