6

I would like to edit the Lock/Unlock button in Experience Editor, in order to enable it for a specific user role. By default, it is only enabled for an admin user and for the user who locked it.

I believe I can do it through the Sitecore LockItem pipeline, but I am struggling a bit. Is there another way?

1
  • Instead of overriding the Lock/Unlock pipeline, can you just give read/write access to the Unlock button for the specific user roles you required? If you still want to do it via code, it will be preferable to replace the current locking button with a custom one Jun 12, 2017 at 21:37

2 Answers 2

2

I don't think you can fix this.. even if you would be able to toggle the button (which is not just setting security), Sitecore is checking the user (admin or user holding the lock) on several locations in code so it will be very hard (if not impossible) to achieve this using the default buttons.

An alternative could be to create a new custom button that gets it done. I would assume you need to switch to an admin user in your code to get the lock away (disabling security might help, but I'm not sure as this is not really a security issue). In that custom code you can create your own security based on the role you want to use.

Information on how to add a custom button can be found here: https://www.sitecore.net/en/company/blog/394/adding-a-custom-button-to-the-ribbon-3919 and here: How do I add a button to the Experience Editor Ribbon?.

1
  • Not sure if I understand correctly - but I think you should add a new button, not replace an existing one.
    – Gatogordo
    May 15, 2019 at 18:20
0

This answer is just to complete @Gatogordo answer :

After you add a custom Unlock button to content editor you need to assign next command to the Unlock button

Create your own class for Unlock Item:

  [Serializable]
  public class UnlockItemCommand : Command
  {

    public override void Execute(CommandContext context)
    {
      Item item = context.Items[0];
      if (item.Access.CanWriteLanguage() && item.Locking.IsLocked())
      {
        Log.Audit(this, "Check in: {0}", new[] {AuditFormatter.FormatItem(item)});
        item.Editing.BeginEdit();
        item.Locking.Unlock();
        item.Editing.EndEdit();
        Context.ClientPage.SendMessage(this, "item:checkedin");
      }
    }


    public override CommandState QueryState(CommandContext context)
    {
      Item item = context.Items[0];
      if (item.Access.CanWriteLanguage() && item.Locking.IsLocked() && !item.Locking.HasLock() && !Context.IsAdministrator)
        return CommandState.Enabled;
      return CommandState.Hidden;
    }
  }

Add your custom command to a new config file located in Include folder:

 <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:x="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <commands>
      <command name="mycommand:unlockitem" type="yourNamespace.UnlockItemCommand,yourAssembly" />   
    </commands>
  </sitecore>
</configuration>

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.