privatebool CreateUIElement() { // Get the module ResourceInfo module = ResourceInfoProvider.GetResourceInfo("MyNewModule"); if (module != null) { // Get the parent UI element UIElementInfo rootElement = UIElementInfoProvider.GetRootUIElementInfo(module.ResourceId); if (rootElement == null) { // Create root UI element rootElement = newUIElementInfo(); rootElement.ElementResourceID = module.ResourceId; rootElement.ElementDisplayName = module.ResourceDisplayName; rootElement.ElementName = module.ResourceName.ToLower().Replace(".", ""); rootElement.ElementIsCustom = false;
// Save root UI element UIElementInfoProvider.SetUIElementInfo(rootElement); }
// Create new UI element object UIElementInfo newElement = newUIElementInfo();
// Set the properties newElement.ElementDisplayName = "My new element"; newElement.ElementName = "MyNewElement"; newElement.ElementResourceID = module.ResourceId; newElement.ElementIsCustom = true; newElement.ElementParentID = rootElement.ElementID;
// Save the UI element UIElementInfoProvider.SetUIElementInfo(newElement);
returntrue;
}
returnfalse; }
The following example gets and updates a UI element.
privatebool GetAndUpdateUIElement() { // Get the UI element UIElementInfo updateElement = UIElementInfoProvider.GetUIElementInfo("MyNewModule", "MyNewElement"); if (updateElement != null) { // Update the properties updateElement.ElementDisplayName = updateElement.ElementDisplayName.ToLower();
// Save the changes UIElementInfoProvider.SetUIElementInfo(updateElement);
returntrue; }
returnfalse; }
The following example gets and bulk updates UI elements.
privatebool GetAndBulkUpdateUIElements() { // Prepare the parameters string where = "ElementName LIKE N'MyNewElement%'";
// Get the data DataSet elements = UIElementInfoProvider.GetUIElements(where, null); if (!DataHelper.DataSourceIsEmpty(elements)) { // Loop through the individual items foreach (DataRow elementDr in elements.Tables[0].Rows) { // Create object from DataRow UIElementInfo modifyElement = newUIElementInfo(elementDr);
// Update the properties modifyElement.ElementDisplayName = modifyElement.ElementDisplayName.ToUpper();
// Save the changes UIElementInfoProvider.SetUIElementInfo(modifyElement); }
returntrue; }
returnfalse; }
The following example adds a UI element to role.
privatebool AddUIElementToRole() { // Get the role RoleInfo role = RoleInfoProvider.GetRoleInfo("cmsdeskadmin", CMSContext.CurrentSiteID);
// Get the UI element UIElementInfo element = UIElementInfoProvider.GetUIElementInfo("MyNewModule", "MyNewElement");
if ((role != null) && (element != null)) { // Create new role UI element object RoleUIElementInfo newRoleElement = newRoleUIElementInfo();
// Set the properties newRoleElement.RoleID = role.RoleID; newRoleElement.ElementID = element.ElementID;
// Save the role UI element RoleUIElementInfoProvider.SetRoleUIElementInfo(newRoleElement);
returntrue; }
returnfalse; }
The following example removes a UI element from role.
privatebool RemoveUIElementFromRole() { // Get the role RoleInfo role = RoleInfoProvider.GetRoleInfo("cmsdeskadmin", CMSContext.CurrentSiteID);
// Get the UI element UIElementInfo element = UIElementInfoProvider.GetUIElementInfo("MyNewModule", "MyNewElement");
if ((role != null) && (element != null)) { // Get the role UI element RoleUIElementInfo deleteElement = RoleUIElementInfoProvider.GetRoleUIElementInfo(role.RoleID, element.ElementID);
// Delete the role UI element RoleUIElementInfoProvider.DeleteRoleUIElementInfo(deleteElement);
return (deleteElement != null); }
returnfalse; }
The following example deletes a UI element.
privatebool DeleteUIElement() { // Get the UI element UIElementInfo deleteElement = UIElementInfoProvider.GetUIElementInfo("MyNewModule", "MyNewElement");
// Delete the UI element UIElementInfoProvider.DeleteUIElementInfo(deleteElement);