IMPORTANT: This version of Sitefinity CMS is out of support and the respective product documentation is no longer maintained and can be outdated. Use the version selector to view a supported product version.
A common requirement for implementing custom features in Sitefinity CMS is the ability to add functionality to the existing back-end screens for managing content.
Most of the back-end screens implementations are based on the so called "definitions" - a data structure that describes or defines the way that both back-end and front-end controls (screens) should look like and behave. The default definitions values are created in memory as configuration elements and not persisted as XML unless someone modifies them through the configurations advanced screens (the advanced configurations UI) or the API. So most of the time those definitions are actually configurations which makes the UI easily user configurable. However there is another very important aspects of those "definitions" data structures. They were designed in a way that enables developers to create or modify them without having to deal with configurations since this should only be an option if you wish your UI to be configurable. This was achieved by implementing simple in memory containers that can't be persisted as configurations but could be serialized and stored in the database.
The IDefinitionExtender interface provides the ability for runtime modification of existing definitions through code without manipulating configurations..
Here is an example implementation of an extender that adds a new command button inside the more actions widget:
public class MyDefinitionsExtender : IDefinitionsExtender
{
public void ExtendDefinition(IContentViewControlDefinition contentViewControlDefinition)
if(this.ShouldExtend(contentViewControlDefinition))
// Not a real selection of view, toolbar, section or items
// just a way to show the depth of the definition and
// where could the desired change be made.
var moreActionsWidgetDefinition = contentViewControlDefinition.Views[0].Toolbar.Sections[0].Items[0];
moreActionsWidgetDefinition.MenuItems.Add(new CommandWidgetDefinition
Name = "buttonName",
Text = "click me",
WrapperTagKey = HtmlTextWriterTag.Li,
CommandName = "customCommandName1",
WidgetType = typeof(CommandWidget)
});
}
Here is how to register your definition extender so that its ExtendDefinition method will be called each time a widget or control receives its definition data structure:
ObjectFactory.Container.RegisterInstance<IControlDefinitionExtender>("MyExtender", new MyDefinitionsExtender(), new ContainerControlledLifetimeManager());
ObjectFactory.Container.RegisterInstance<
IControlDefinitionExtender
>("MyExtender", new MyDefinitionsExtender(), new ContainerControlledLifetimeManager());
Back To Top
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important