1

So the current project on which i am working, does not have workflow set and the client needs a barrier against accidental content publish. Now, if I mark "Never Publish" on the standard value of the templates, All the items will be deleted from the web database.

Is there a way to set all the items created henceforth to never publish ?

1

You can add custom hander to item:created event and set the value of Never Publish to true:

public void OnItemCreated(object sender, EventArgs args)
{
    var createdArgs = Event.ExtractParameter(args, 0) as ItemCreatedEventArgs;

    Assert.IsNotNull(createdArgs, "args");
    if (createdArgs != null)
    {
        Assert.IsNotNull(createdArgs.Item, "item");
        if (createdArgs.Item != null)
        {
            Item item = createdArgs.Item;
            item.Editing.BeginEdit();
            item.Publishing.NeverPublish = true;
            item.Editing.EndEdit();
         }
    }
}

and register it via patch file:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <events>
      <event name="item:created">
        <handler type="My.Assembly.Namespace.ClassName, My.Assembly" method="OnItemCreated" />
      </event>
    </events>
  </sitecore>
</configuration>
  • Thanks @Marek Musielak sometimes the solution is right in front of you but you are too consumed with a specific set of solutions – Shabaaz Shaikh May 20 at 6:31
2

If you want a code-less approach, just create a Branch Template based on your item template, and set the publishing restrictions on the default item of the branch.

enter image description here

And

enter image description here

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.