Attaching elements

Step 15 - Adding Workflow Action to Page Elements

Our final step, is adding a workflow action to the page elements.

The creation of workflows is beyond the scope of the tutorial, so we use reuse the existing edit page workflow.

[ConfigurationElementType(typeof(NonConfigurableElementAttachingProvider))]
public sealed class MyElementAttachingProvider : IElementAttachingProvider
{  
  // ...the code skipped for readability - see Step 3, 7, 10, 14
  private static readonly ActionGroup ActionGroup = 
    new ActionGroup("My tasks", ActionGroupPriority.PrimaryLow);
  private static ResourceHandle EditPage = GetIconHandle("page-edit-page");
  // ...the code skipped for readability - see Step 3, 7, 10, 14
  public IEnumerable<Element> GetChildren(EntityToken parentEntityToken, 
                      Dictionary<string, string> piggybag)
  {
    using (DataConnection connection = new DataConnection())
    {
      if ((parentEntityToken is MyRootEntityToken) == true)
      {
         // ...the code skipped for readability - see Step 3, 7, 10, 14
      }
      else
      {
         // ...the code skipped for readability - see Step 3, 7, 10, 14
        foreach (IPage page in pages)
        {
          Element element = 
           new Element(this.Context.CreateElementHandle(page.GetDataEntityToken()))
          {
            VisualData = new ElementVisualizedData
            {
              Label = page.Title,
              ToolTip = page.Title,
              HasChildren = false,
              Icon = icon
            }
          };
         // ...the code skipped for readability - see Step 3, 7, 10, 14
           element.AddAction(
             new ElementAction(new ActionHandle(new WorkflowActionToken(
             WorkflowFacade.GetWorkflowType(
"Composite.StandardPlugins.Elements.ElementProviders.PageElementProvider.EditPageWorkflow"), 
             new PermissionType[] { PermissionType.Administrate })))
          {
            VisualData = new ActionVisualizedData
            {
              Label = "Edit page",
              ToolTip = "Eidt page",
              Icon = EditPage,
              Disabled = false,
              ActionLocation = new ActionLocation
              {
                ActionType = ActionType.Edit,
                IsInFolder = false,
                IsInToolbar = true,
                ActionGroup = ActionGroup
              }
            }
          });
          yield return element;
        }    
      }
    }
  }
  // ...the code skipped for readability - see Step 3, 7, 10, 14
}

Adding a workflow action is similar to adding our URL action. It’s just done with a different action token type.