LibrarySites.Banner

Fields that Control Publishing Restrictions in the Sitecore ASP.NET CMS

This blog post contains information about the fields defined by the standard template that control publishing restrictions for items in the Sitecore ASP.NET web Content Management System (CMS) and Customer Engagement Platform (CEP).

Sitecore uses fields defined by the standard template to control publishing restrictions.

In the following table, the first column indicates the property of the Sitecore.FieldIDs class that exposes the ID of the field. With this ID, you can access the field like you would any other field of the item.

The second column indicates the name of the field. You may wish to use the name to make your code more clear when you cannot easily use the ID.

The third column indicates how Sitecore represents the value of the field, such as the Sitecore.Data.Items.Item.Publish.PublishDate property. The Sitecore.Data.Items.Item provides a property named Publish of type Sitecore.Data.Items.ItemPublishing, which exposes a property named PublishDate that contains the value of the relevant field.

The fourth column indicates whether the field is shared (whether Sitecore shares the value of the field among all versions in all languages). All fields that are not shared are versioned.

Sitecore.FieldIDs. Field Name Sitecore.Data.Items.Item. Shared
PublishingTargets __Publishing groups   Shared
PublishDate __Publish Publish.PublishDate Shared
NeverPublish __Never publish Publish.NeverPublish Shared
UnpublishDate __Unpublish Publish.UnpublishDate Shared
ValidFrom __Valid from Publish.ValidFrom  
FieldIds.ValidTo __Valid to Publish.ValidTo  
HideVersion __Hide version Publish.HideVersion  
State __Workflow state    

You can use APIs to determine the latest publishable version of an item given existing publishing restrictions, if any. Specifically, you can access the GetValidVersion() method of the Sitecore.Data.Items.ItemPublishing instance exposed by the Publishing property of the item. For example, to determine the version of the context item to publish in the context language:

Sitecore.Data.Items.Item version = Sitecore.Context.Item.Publishing.GetValidVersion(
  this.Options.PublishDate,
  true /*requireApproved*/);
 
if (version != null)
{
  // version indicates publishable version
}

Resources

  • Hi John. I'd assumed I could restrict publishing (using 'never publish') by language but cannot because the field is shared. What are the implications of unsharing this field? I can see it would solve my issue but I'm not sure what other implications there may be. Thanks!

  • I always try to avoid altering the standard template, because not only could it affect system functionality, but it could present upgrade challenges. Therefore I would try to find another solution. Can you describe your requirements? Is there some logic that you could use to determine which languages of which items not to publish? Can you explain why you want to do that? Could you use workflow for that restriction, or maybe a publishItem pipeline (possibly using a field in a custom template that you add to the standard template)?

  • Hi John, question about this.  I am using item.Publishing.GetValidVersion([date], true) on an item where the "Never publish" checkbox is checked.  Content Editor correctly tells me that this item won't be published (and it is not).  But when I use item.Publishing.GetValidVersion([date], true/false), I am getting back the item instead of the expected null.  Am I using this incorrectly?

  • @Bryan: I think there are two separate content editor warning processors involved here - one for version publishing and one for item publishing.  I think you would need to add code something like:  ItemPublishingRestrictedError error = PublishingInformationBuilder.GetPublishingInformation(item, PublishingInformationLevel.Item).OfType<ItemPublishingRestrictedError>().FirstOrDefault<ItemPublishingRestrictedError>();          if (error != null)         { // cannot publish         }     } }