# Widget Registration and Initialization

A widget needs to register itself with the portal it is contained within. It does this having a class with that implements the IWidgetRegistration interface

public interface IWidgetRegistration
{
    int Register();
    int RegisterPortal(string portalId);
}
1
2
3
4
5

# Register

The class' Register method is called during the Application_Start cycle of your website. This is the location you typically place code to

# Register your widget's AJAX endpoints (routes)

RouteTable.Routes.MapRoute(
    "Blog_route",
    "blogapi/{controller}/{action}/{id}",
    new { action = "Index", id = UrlParameter.Optional },
    null,
    new string[] { "Videre.Blog.Widgets" }
);
1
2
3
4
5
6
7

# Register your widget manifest

var updates = Videre.Core.Services.Update.Register(new List()
{
  new CoreModels.WidgetManifest() { Path = "Core/Account", Name = "UserProfile", Title = "User Profile", Category = "Account" }
});
1
2
3
4

# Register any portal Attribute Definitions (configuration values specific to your widget)

CoreServices.Update.Register(new CoreModels.AttributeDefinition() { GroupName = "Core", 
    Name = "SearchIndexDir", DefaultValue = "~/App_Data/SearchIndex", Required = true, 
    LabelKey = "SearchIndexDir.Text", LabelText = "Search Index Directory" });
1
2
3

# RegisterPortal

Similar to the Register method, the RegisterPortal method is called during application start as well, only it gets called for each portal your CMS may be hosting. Settings that are portal specific get initialized here. Typically you place code here to

# Register any Secure Activities

updates += CoreServices.Update.Register(new List()
{
    new CoreModels.SecureActivity() { PortalId = portalId, Area = "Portal", Name = "Administration", 
        RoleIds = new List() {CoreServices.Update.GetAdminRoleId(portalId)} }
});
1
2
3
4
5

# Any portal specific customization code

public int RegisterPortal(string portalId)
{
    var updates = 0;
    updates += CoreServices.Update.Register(new List<CoreModels.Role>()
    {
        new CoreModels.Role() { Name = "admin", PortalId = portalId, Description = "Administrative Priviledges" }
    });
    return updates;        
}
1
2
3
4
5
6
7
8
9