sitecoresitecore7sitecore7.1sitecore-workflow

Sitecore workflow - publishing item in draft state


I am currently working with sitecore items that are in a draft workflow state. The following happens:

This causes our controls to render the item but with standard values because there are no versions. Of course we could add a check for item.Versions.Count > 0 but my question is why this is happening?

Surely an item in draft workflow state should never appear in the web database in any way?

The workflow being used is pretty standard and has no customisation. The states and commands are:

Thanks in advance.


Solution

  • I believe you can use the following property on each of your site nodes in the config.

    <site name="website" filterItems="true" ... />
    

    If setting this to true doesn't resolve the issue then you can add the following pipeline step, in addition to the above setting, before the Sitecore.Pipelines.FilterItem.EnsureFilteredItem step.

    public class HideEmptyItem
    {
        public void Process(FilterItemPipelineArgs args)
        {
            if ((Context.Site != null && Context.Site.DisplayMode == DisplayMode.Normal) && args.Item.Paths.Path.StartsWith("/sitecore/content/"))
            {
                try
                {
                    Context.Site.DisableFiltering = true;
                    if (args.Item.Database.GetItem(args.Item.ID, Context.Language).Versions.Count == 0)
                    {
                        args.FilteredItem = null;
                    }
                }
                finally
                {
                    Context.Site.DisableFiltering = false;
                }
            }
        }
    }
    

    Also ensure the following is set accordingly, the default is false;

    <setting name="Publishing.PublishEmptyItems" value="false" />
    

    I actually encountered this issue but in a different way. If you use publishing restrictions you can end up with an item that has no versions on it but can still be published. There are many ways for an item to end up with no versions, not just a new item with a single version that hasn't been pushed through a workflow. The above fix was actually provided by Sitecore support and worked for me.

    If this doesn't work for you then I would suggest adding in check when items are published to see if they have any versions, although I believe that's what the fix above is supposed to do.

    EDIT: Changed property from "hideEmptyItems" to "filterItems" and added further explanation.