5

I recently discovered a checkbox on the "View" ribbon of the Experience Editor in Sitecore 8.1. This checkbox is used to display validation errors, but it is not checked by default.

Checkbox

How would I go about enforcing the following:

  1. The checkbox is checked by default
  2. The checkbox cannot be unchecked (my thinking is to just deny the read/write permission for this button. I just need to make sure it's checked first).
8

The value of the checkbox is set on a per user basis and stored against their profile (which means it is remembered across sessions and browsers/computers).

Force Field Validation to be Enabled

To force this checkbox to be enabled, you can set it against the user profile when they log in.

using Sitecore.Diagnostics;
using Sitecore.Pipelines.LoggedIn;
using Sitecore.Security.Accounts;
using Sitecore.Web.UI.HtmlControls;

namespace MyProject.CMS.Pipelines.LoggedIn
{
    public class UserLoggedIn
    {
        public void Process(LoggedInArgs args)
        {
            User user = User.FromName(args.Username, true);
            Assert.IsNotNull(user, "user");
            Registry.SetValue("/Current_User/Page Editor/Capability/FieldsValidation", "on");
            // Sitecore.ExperienceEditor.Constants.CheckboxTickedRegistryValue can also be used 
            // as a constant to "on" but you'll need to add a reference to the DLL
        }
    }
}

Then patch this into the loggedin pipeline:

<sitecore>
  <processors>
    <loggedin>
      <processor mode="on" type="MyProject.CMS.Pipelines.LoggedIn.UserLoggedIn, MyProject.CMS" /> 
    </loggedin>
  </processors>
</sitecore>

Force Checkbox to be Disabled

Edit the JS file located in /sitecore/shell/client/Sitecore/ExperienceEditor/Commands/EnableFieldsValidation.js and update the canExecute function to return false:

canExecute: function (context) {
  return false;
},

The checkbox should now appear checked and not changeable. You may have to force refresh the browser cache to pick up the updated JS file.

Field Validation

  • The only thing I'm hesitant to do is modify the JS file. I may end up leaving the checkbox as togglable. As long as when they re-log in it gets checked, I think we're ok. – Ben Lipson Dec 5 '16 at 16:23
  • 1
    @BenLipson Sure, that's understandable. But I wanted to provide you with a full answer :) – jammykam Dec 5 '16 at 17:37
5

Go to core db. Find the: "/sitecore/content/Applications/WebEdit/Ribbons/WebEdit/View/Capabilities/Field validation"

Now you can see the "webedit:hidecontrol" is used.

<command name="webedit:hidecontrol" type="Sitecore.ExperienceEditor.WebEdit.Commands.HideControl, Sitecore.ExperienceEditor" />

[Serializable]
public class HideControl : WebEditCommand
{
    // Methods
    public override void Execute(CommandContext context)
    {
    }

    public override CommandState QueryState(CommandContext context) => 
        CommandState.Hidden;
}

Add your own command and update the method QueryState with CommandState.Enabled or CommandState.Down.

Hope it helps.

  • you beat me with your answer. Love it :). – phani Dec 2 '16 at 18:39
  • I just tried creating a class that extends HideControl and replacing the type of this command with the new one. The checkbox is still unchecked by default, and the validator is not active. I also tried just creating a new command and assigning it, and it didn't make a difference. I checked ShowConfig.aspx and it does indicate webedit:hidecontrol uses my new type. – Ben Lipson Dec 2 '16 at 19:42
  • You are right. It doesn't work. Sorry. I will try to figure out. I see I missed StringUtility.EvaluateCheckboxRegistryKeyValue – Vlad Shpak Dec 2 '16 at 23:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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