2

I have 3 items in a folder based on the same template. Is there any functionality provided by Sitecore to prevent these items from being moved to another folder accidentally or deliberatively? Or we can apply any validation on the template like if an item is created on the base of this template it cannot be moved. You can only edit, copy or delete it. Thanks for the help.

2
  • Can you add a subscriber to the item:moving event? Mar 4, 2019 at 14:30
  • Yeah did that, thanks for the help @MichaelWest
    – PSS
    Mar 4, 2019 at 15:43

1 Answer 1

4

There is nothing like that out of the box in Sitecore. But you can easily create such a functionality on your own:

  1. Create a new template with one field only - checkbox "Cannot be moved"
  2. Add your handler to <event name="item:moving"/>
  3. In the handler code cancel the event if the checkbox is checked.

I haven't tested the code but something like this should do the trick:

  protected void OnItemMoving(object obj, EventArgs args)
  {
      if (JobContext.IsJob && JobContext.Job.Category == "publish")
          return;

      SitecoreEventArgs evt = args as SitecoreEventArgs;
      Item item = Event.ExtractParameter(args, 0) as Item;

      if (MainUtil.GetBool(item["Cannot be moved"], false))
        this.CancelEvent(evt);
  }

And as Dan Sinclair suggested:

You may want to apply field level security to that Cannot be moved field, too, to ensure that savvy content editors don't work around it. :)

5
  • You may want to apply field level security to that Cannot be moved field, too, to ensure that savvy content editors don't work around it. :) Mar 4, 2019 at 14:33
  • @DanSinclair smart! I added your comment to the answer
    – Marek Musielak
    Mar 4, 2019 at 14:35
  • @MarekMusielak This is working great. Thanks for the help guys.
    – PSS
    Mar 4, 2019 at 15:42
  • I'm glad I could help. If this answer worked for you, you may want to mark it as "Accepted" so further visitors will know that it works.
    – Marek Musielak
    Mar 4, 2019 at 15:54
  • @MarekMusielak Sure.
    – PSS
    Mar 4, 2019 at 16:43

Your Answer

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

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