This feature appeared in Sitecore 8.2, which is changing the workflow state value for datasource items together with the context page item (only in Experience Editor). Here is a great summary article related to these improvements.
I was not fully satisfied with this because by default this only collects the datasource items and does not the children items of a datasource. This is an issue when you have something like a list component which shows the children items. What I have found is:
<command name="webedit:workflowwithdatasourceitems" type="Sitecore.ExperienceEditor.WebEdit.Commands.WorkflowWithDatasourceItems, Sitecore.ExperienceEditor" />
So I just needed to overwrite this command and put my logic there:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Sitecore; | |
using Sitecore.ExperienceEditor.Utils; | |
using Sitecore.ExperienceEditor.WebEdit.Commands; | |
using Sitecore.Workflows.Simple; | |
using System.Linq; | |
namespace Helix.Skeleton.Foundation.ContentWorkflow.Commands | |
{ | |
public class WorkflowWithDatasourceItemsAndChildren : WorkflowWithDatasourceItems | |
{ | |
protected new void WorkflowCompleteCallback(WorkflowPipelineArgs args) | |
{ | |
base.WorkflowCompleteCallback(args); | |
var datasources = ItemUtility.GetItemsFromLayoutDefinedDatasources( | |
args.DataItem, | |
Context.Device, | |
args.DataItem.Language); | |
foreach (var child in ItemUtility.FilterSameItems(datasources).SelectMany(d => d.Children)) | |
{ | |
if (child.Access.CanWrite() && (!child.Locking.IsLocked() || child.Locking.HasLock())) | |
{ | |
WorkflowUtility.ExecuteWorkflowCommandIfAvailable( | |
child, | |
args.CommandItem, | |
args.CommentFields); | |
} | |
} | |
} | |
} | |
} |
And the related config what I have mentioned above:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8" ?> | |
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> | |
<sitecore> | |
<commands> | |
<command name="webedit:workflowwithdatasourceitems" type="Helix.Skeleton.Foundation.ContentWorkflow.Commands.WorkflowWithDatasourceItemsAndChildren, Helix.Skeleton.Foundation.ContentWorkflow" /> | |
</commands> | |
</sitecore> | |
</configuration> |
One thought on “WebEdit.AffectWorkflowForDatasourceItems – collect datasource children items”