• About this blog
  • About me
  • Contact
Sitecore XperiencesThe things I've seen as a Sitecore Professional
  • About this blog
  • About me
  • Contact
Menu
  • About this blog
  • About me
  • Contact
  • Custom Reset Layout in Content and Experience Editor Modes

    February 9, 2018 Rodrigo Peplau 0

    Custom-Reset-Layout-in-Content-and-Experience-Editor-Modes

    Recently I had to customize the code that triggers when a Reset Layout is executed. If you ever had to attach any code to it, this post is for you!

    You know, that sympathetic prompt:

    Reset Layout Prompt

    The first thing you need to know is that Content Editor and Experience Editor does that differently, so let’s go for them:

    Round 1 – Content Editor

    Content Editor uses a command for that (pagedesigner:reset), which is natively implemented by the class Sitecore.Shell.Applications.Layouts.PageDesigner.Commands.Reset. We first need to create a class that will inherit from the original, so we don’t lose the original behavior, and implement our custom logic on it.

    Create a Command class like this:

    using System.Web.Mvc;
    using Sitecore.Shell.Applications.Dialogs.ResetLayout;
    using Sitecore.Web.UI.Sheer;
    
    namespace MyProject.Commands
    {
        public class ResetLayoutCommand : Sitecore.Shell.Applications.Layouts.PageDesigner.Commands.Reset
        {
            protected override void Run(ClientPipelineArgs args)
            {
                // Runs the default behaviour
                base.Run(args);
    
                // Skips if the Reset Layout prompt is not submited or results is undefined
                if (!args.IsPostBack || string.IsNullOrEmpty(args.Result) || args.Result == "undefined")
                    return;
    
                // Takes the item that has been reset
                var itemReset = DeserializeItems(args.Parameters["items"])[0];
    
                // And here is where your custom logic will be implemented
                // .....
            }
        }
    }

    Then we override the default command with our class in a config patch like this:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
        <sitecore>
            <commands>
                <command patch:instead="*[@name='pagedesigner:reset']" name="pagedesigner:reset" resolve="true" 
                    type="MyProject.Commands.ResetLayoutCommand, MyProject"/>
            </commands>
        </sitecore>
    </configuration>

    And this is how we run the first leg. But it is not over yet, let’s go for…

    Round 2 – Experience Editor

    Experience Editor, on the other hand, uses a different approach for that. It has a request node named “ExperienceEditor.ResetLayout.Execute” under <sitecore.experienceeditor.speak.requests> that we need to replace. This request node is implemented by the native class Sitecore.ExperienceEditor.Speak.Ribbon.Requests.ResetLayout.Execute, which again we are going to inherit.

    So our Request class will be like this:

    using System;
    using System.Web.Mvc;
    using Sitecore.Diagnostics;
    using Sitecore.ExperienceEditor.Speak.Attributes;
    using Sitecore.ExperienceEditor.Speak.Server.Responses;
    using Sitecore.Shell.Applications.Dialogs.ResetLayout;
    
    namespace MyProject.ExperienceEditor
    {
        public class ResetLayout : Sitecore.ExperienceEditor.Speak.Ribbon.Requests.ResetLayout.Execute
        {
            [HasItemPermissions(Id = "{BE98D7F0-7404-4F97-8E4C-8FEF4ACA5DA3}", Path = "/sitecore/content/Applications/WebEdit/Ribbons/WebEdit/Advanced/Layout/Reset")]
            public override PipelineProcessorResponseValue ProcessRequest()
            {
                // Instantiates the returning object and 
                var processorResponseValue = new PipelineProcessorResponseValue();
    
                try
                {
                    // Executes the default RESET LAYOUT process
                    processorResponseValue = base.ProcessRequest();
    
                    // Takes the item that has been reset
                    var itemReset = RequestContext.Item;
    
                    // And here is where your custom logic will be implemented
                    // ..... (OF COURSE, DON'T DUPLICATE YOUR LOGIC!)
                }
                catch (Exception e)
                {
                    Log.Error(
                        $"[ResetLayout] Cannot execute post Layout Reset operations to item '{RequestContext.Item.Paths.Path}'", e, GetType());
                }
                return processorResponseValue;
            }
        }
    }

    And finally we patch it again with a config file like this:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
        <sitecore>
            <sitecore.experienceeditor.speak.requests>
                <request patch:instead="*[@name='ExperienceEditor.ResetLayout.Execute']"
                    name="ExperienceEditor.ResetLayout.Execute"
                    type="MyProject.ExperienceEditor.ResetLayout, MyProject" />
            </sitecore.experienceeditor.speak.requests>
        </sitecore>
    </configuration>

    And that’s all… You now have your custom code being triggered by both Content Editor and Experience Editor!

    Categories: Content Edition Experience, Development, Experience Editor

    Sitecore 9 Update 1 - Bug saving Shared Layout in Experience Editor Powershell script to find TDS files with length error

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Proudly 10x Sitecore MVP!
(2016-2025)

Localization

Recent Posts

  • All Submissions from Sitecore Hackathon 2025!
  • Know your Media Library disk usage with a simple PowerShell script
  • Automated Behavioral Personalization in Sitecore XP with Generative AI
  • MVPinny knows the Sitecore Accelerate for Partners
  • Rodrigo Peplau wins Sitecore Most Valuable Professional award

Recent Comments

  • navan on Meet MVPinny: the AI-Powered Sitecore Assistant
  • Adriana on Content generation with Sitecore Connect and ChatGPT
  • NAVAN on Automatic Sitecore NuGet upgrades with Powershell
  • Hedipo S Menezes on Corey Peplau wrote this - WFFM conflict with Unity DI and a lesson on how Sitecore community is so amazing
  • Rodrigo Peplau on ERROR [Content Testing]: Cannot find PhantomJS executable at ' (...) /data/tools/phantomjs/phantomjs.exe'. Aborting screenshot generation.

Archives

  • March 2025
  • January 2025
  • June 2024
  • April 2024
  • February 2024
  • December 2023
  • November 2023
  • August 2023
  • July 2023
  • January 2023
  • February 2022
  • December 2021
  • November 2021
  • March 2021
  • July 2020
  • February 2020
  • September 2019
  • July 2019
  • April 2019
  • March 2019
  • December 2018
  • February 2018
  • January 2018
  • November 2017
  • September 2017
  • August 2017
  • July 2017
  • March 2017
  • February 2017
  • November 2016
  • September 2016
  • August 2016
  • July 2016
  • April 2016
  • November 2015
  • September 2015
  • July 2015
  • April 2015
  • March 2015
  • February 2015

Categories

  • Actions
  • Active Directory
  • Analytics
  • Architecture
  • Bug fixing
  • CDP/Personalize
  • ChatGPT
  • Content Edition Experience
  • Content Hub
  • Continuous Integration
  • Dev
  • Development
  • Environments
  • Experience Editor
  • Experience Forms
  • Front-end
  • Hackathon
  • Health Check builds
  • Helix
  • How To
  • LDAP
  • MVP
  • MVP Summit
  • MVPinny
  • Phantom JS
  • Powershell
  • QA
  • Richtext Editor
  • Rules
  • Security Provider
  • SIF
  • Sitecore 9
  • Sitecore API
  • Sitecore Community
  • SItecore Connect
  • Sitecore Modules
  • Sitecore Rocks
  • Sitecore Rule Processor
  • Sitecore Symposium
  • SPE
  • SPE-only Alliance
  • SPEAK
  • SUG
  • Support Ticket
  • TDS
  • Team City
  • Uncategorized
  • Upgrades
  • Visual Studio
  • WFFM
  • Workflow
  • XConnect
  • xDB
  • XM Cloud

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

Recent Posts

  • All Submissions from Sitecore Hackathon 2025!
  • Know your Media Library disk usage with a simple PowerShell script
  • Automated Behavioral Personalization in Sitecore XP with Generative AI
  • MVPinny knows the Sitecore Accelerate for Partners
  • Rodrigo Peplau wins Sitecore Most Valuable Professional award
  • Error enabling GraphQL IDE with XM Cloud
  • Meet MVPinny: the AI-Powered Sitecore Assistant
  • Content generation with Sitecore Connect and ChatGPT
  • XM Cloud Starter Kit with Content Hub Integration
  • Meet the (Brand new) Advanced Powershell Packaging Features

Tag Cloud

    Architecture Automation Continuous Integration Debugging Development Environments Hackathon How To PhantomJS Powershell Server Roles TDS Team City Team Development for Sitecore XConnect

Pages

  • About this blog
  • About me
  • Contact

Search

Copyright © 2015 Rodrigo Peplau Theme created by PWT. Powered by WordPress.org