1

We want to always open shared layout in experience editor for our authors. We are using Sitecore 10.1.1.

As we have Sitecore 10.1.1 with azure ad login integration so, solution provided in link does not help:

Force shared layout in experience editor

Sitecore stores the user selection of layout in registry key EditAllVersions, I tried the solution provided in link:

https://blogs.perficient.com/2021/05/09/manage-users-registry-settings-after-login/

to always set the key EditAllVersions to on each time user logins.

But my custom Processor is not getting called every time when I login to Sitecore so the value of registry key ("{ "/Current_User/Page Editor/Show/EditAllVersions", "on" }") does not get updated. I am patching my processor after: "Sitecore.Owin.Authentication.Pipelines.CookieAuthentication.SignedIn.CleanupUserProfile" as mentioned in solution.

Any ideas what I am missing out here?

9
  • Where you added your patch file? Are you able to see the entry in showconfig? Mar 3, 2023 at 16:21
  • Please, provide your patching config file Mar 3, 2023 at 16:23
  • I included my patch file under include folder. I was able to see it in showconfig. The processor gets called but the behavior is not consistent. It is not getting called every time I refresh or login again. Mar 3, 2023 at 16:26
  • <?xml version="1.0" encoding="utf-8" ?> <configuration xmlns:patch="sitecore.net/xmlconfig" xmlns:set="sitecore.net/xmlconfig/set"> <sitecore> <pipelines> <owin.cookieAuthentication.signedIn> <processor patch:after="processor[@type='Sitecore.Owin.Authentication.Pipelines.CookieAuthentication.SignedIn.CleanupUserProfile, Sitecore.Owin.Authentication']" type="XXX.SetUserRegistry, XXX" /> </owin.cookieAuthentication.signedIn> </pipelines> </sitecore> </configuration> Mar 3, 2023 at 16:29
  • 1
    @Marcel Gruber This is a business requirement. They want content authors to always start editing the shared layout while creating new items so they don't have to add renderings again for different language versions incase forget to select the correct layout. Mar 3, 2023 at 19:04

3 Answers 3

3

I achieved this by writing a custom processor in the "GetPageEditorNotificationsProcessor" pipeline. This will be called every time a user opens Experience Editor mode. In the processor I updated the registry key to show shared layout and also added a notification message for user if they open final layout.

Code of the processor:

public class SetExperienceEditorLayout : GetPageEditorNotificationsProcessor
    {
        public override void Process(GetPageEditorNotificationsArgs arguments)
        {
            Assert.ArgumentNotNull(arguments, "arguments");
            bool editingSharedVersion = WebUtility.IsEditAllVersionsTicked();
            if (!editingSharedVersion)
            {
                arguments.Notifications.Add(new PageEditorNotification("You are editing the final layout"), PageEditorNotificationType.Warning));             
                Registry.SetString(Constants.RegistryKeys.EditAllVersions,
                          Constants.Registry.CheckboxTickedRegistryValue);
            }
        } 

Config to patch the processor:

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <sitecore>
    <pipelines>
      <group groupName="ExperienceEditor" name="ExperienceEditor">
        <pipelines>
          <getPageEditorNotifications>
            <processor patch:after="processor[@type='Sitecore.ExperienceEditor.Pipelines.GetPageEditorNotifications.LanguageAccessNotification, Sitecore.ExperienceEditor']" type="MyProject.Sitecore.Pipeline.SetExperienceEditorLayout, MyProject.Sitecore" />
          </getPageEditorNotifications>
        </pipelines>
      </group>
    </pipelines>
  </sitecore>
</configuration>
0

I verified the code with my vanilla Sitecore 10.1 version and used the same class as shown in the article you mentioned.

https://blogs.perficient.com/2021/05/09/manage-users-registry-settings-after-login/

Here is my config

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <sitecore>
    <pipelines>
      <owin.cookieAuthentication.signedIn>
        <processor patch:after="processor[@type='Sitecore.Owin.Authentication.Pipelines.CookieAuthentication.SignedIn.CleanupUserProfile, Sitecore.Owin.Authentication']" type="Mysite.Custom.Pipelines.CookieAuthentication.SignedIn.SetUserRegistry, WebApplication1" />
      </owin.cookieAuthentication.signedIn>
    </pipelines>
  </sitecore>
</configuration>

And I put the config in the following location

\wwwroot\<my-site-root>\App_Config\Include\zzz\Pipelines.UserRegistry.config

When I logged in to Sitecore, I was able to debug it and it set all the registry items of the user.

Finally, when I opened a page in the experience editor mode, It showed the Shared Layout to me.

enter image description here

Try adding your config in the same location that I used in the App_Config\Include\zzz and it should work.

Thanks

4
  • Thanks Sumit for your answer. Is it happening every time? I mean if you change your layout from shared to final and then logout and login again, then also the layout changes back to shared(as per custom logic, at login registry key is set again) or it remains final (as per your last preference)? Mar 3, 2023 at 18:51
  • @litikachib every time you log in, it runs and when you change the layout from shared to final then it will remain the final. Next time when you log in again, it will set it to shared. Hope this helps. This is the same implementation that you are referring from the blog you shared. Mar 4, 2023 at 4:58
  • Did you verify it with Azure AD Integration? Mar 6, 2023 at 9:21
  • Thanks for your input. I achieved this but writing a custom processor in "GetPageEditorNotificationsProcessor" pipeline. This will be called every time user opens experience editor mode. In the processor I updated the registry key to show shared layout and also added a notification message for user if they open final layout. Mar 9, 2023 at 21:29
0

If the owin.cookieAuthentication.signedIn processor is not triggering consistently, it may be due to the fact that the CleanupUserProfile processor is clearing the user context before your custom processor can run.

One way to ensure that your processor runs before the CleanupUserProfile processor is to patch your processor before it in the CookieAuthentication pipeline, like so:

<configuration>
  <sitecore>
    <pipelines>
      <owin.cookieAuthentication.signedIn>
        <processor patch:before="processor[@type='Sitecore.Owin.Authentication.Pipelines.CookieAuthentication.CleanupUserProfile, Sitecore.Owin.Authentication']" type="Your.Namespace.Here.SetUserRegistry, Your.Assembly.Name" />
      </owin.cookieAuthentication.signedIn>
    </pipelines>
  </sitecore>
</configuration>

This should ensure that your custom processor runs before the CleanupUserProfile processor and can set the registry key value consistently.

3
  • Tried patching my processor before the CleanupUserProfile, but still no luck. Mar 3, 2023 at 17:44
  • @litikachib let me ask one more time. Is it firing processor if your will sign in with 'admin' user as not an Azure AD account? Does it happen only in case of Azure AD? Mar 6, 2023 at 9:22
  • I tried with both users, Admin as well as with Azure AD integration. The behavior is not consistent. First time it works, then if I change the layout from shared to final, then after login again it is not resetting back to shared. Mar 6, 2023 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.