Attaching elements
Step 3: Making Attaching Element Provider
Now we are ready to make our attaching element provider that will show our new root element.
[ConfigurationElementType(typeof(NonConfigurableElementAttachingProvider))] public sealed class MyElementAttachingProvider : IElementAttachingProvider { public ElementProviderContext Context { get; set; } public bool HaveCustomChildElements(EntityToken parentEntityToken, Dictionary<string, string> piggybag) { if (ElementAttachingPointFacade.IsAttachingPoint(parentEntityToken, AttachingPoint.ContentPerspective) == false) return false; return true; } public ElementAttachingProviderResult GetAlternateElementList( EntityToken parentEntityToken, Dictionary<string, string> piggybag) { if (ElementAttachingPointFacade.IsAttachingPoint(parentEntityToken, AttachingPoint.ContentPerspective) == false) return null; ElementAttachingProviderResult result = new ElementAttachingProviderResult() { Elements = GetRootElements(piggybag), Position = ElementAttachingProviderPosition.Bottom, PositionPriority = 0 }; return result; } private IEnumerable<Element> GetRootElements(Dictionary<string, string> piggybag) { yield return new Element(this.Context.CreateElementHandle(new MyRootEntityToken())) { VisualData = new ElementVisualizedData { Label = "Page state overview", ToolTip = "Page state overview", HasChildren = true, Icon = CommonElementIcons.Folder } }; } public IEnumerable<Element> GetChildren(EntityToken parentEntityToken, Dictionary<string, string> piggybag) { throw new NotImplementedException("Will be later in the tutorial"); } }
First, the ConfigurationElementType attribute is used to specify if this plug-in has its own configuration in the Composite.config file or – as in our case - has no configuration at all. You’ll read more on the configuration later.
ElementProviderContext
This is set by C1 CMS and is used for creating ElementHandle’s, which - combined with an entity token - make the identity of the element. For now you only need to save this in the setter and use it later on when creating new elements.
HaveCustomChildElements
This method is used to tell C1 CMS that an existing element in the tree - the one you want your element(s) to be attached under has children (your elements).
GetAlternateElementList
This is the actual method that attaches your elements to the existing tree. This is done through the ElementAttachingProviderResult class where you can specify if your elements should be put at the top or at the bottom and a priority that is used if more than one ElementAttachingProvider is attaching elements to the same one as you do. This method calls the GetRootElements described below.
GetRootElements
This is where the actual magic happens. The most important thing here is this line:
return new Element(this.Context.CreateElementHandle(new MyRootEntityToken()))
Here you can see that the Context is used for creating the element handle and we use our root entity token MyRootEntityToken.
GetChildren
At this point we don’t have any children to our root element, so this is left empty.