Anders Hattestad
Jun 22, 2011
  5326
(2 votes)

How to change built in properties

If you want to change tab a built in property are placed in there are several ways of doing this. But one way is to make your self an Edit Panel plugin. If you implements ICustomPlugInLoader and always returns a empty array, there are no need for a ascx file.

Code Snippet
  1. [GuiPlugIn(Area = PlugInArea.EditPanel)]
  2. public class ChangeBuiltInProperties : EPiServer.UserControlBase, ICustomPlugInLoader
  3. {
  4.     public PlugInDescriptor[] List()
  5.     {
  6.         var editPanel = HttpContext.Current.Handler as EditPanel;
  7.         if (null != editPanel)
  8.             editPanel.LoadComplete += editPanel_LoadComplete;
  9.         return new PlugInDescriptor[] { };
  10.     }

You can then in the List() method hook up to the LoadCompleted event, and there get access hook up to the Populate event

Code Snippet
  1. private void editPanel_LoadComplete(object sender, EventArgs e)
  2. {
  3.     var dataForm = FindControl<PropertyDataForm>((Control)sender, null);
  4.     if (dataForm != null)
  5.         dataForm.Populate += new EventHandler(dataForm_Populate);
  6. }

You can then change the OwnerTab for a property.

Code Snippet
  1. void dataForm_Populate(object sender, EventArgs e)
  2. {
  3.     var dataForm = sender as PropertyDataForm;
  4.     //todo: use PageTypeBuilder tabs
  5.     var moveToTab=EPiServer.DataAbstraction.TabDefinition.Load("Information");
  6.     var moveFromTab=EPiServer.DataAbstraction.TabDefinition.Load("Scheduling");
  7.     foreach (var item in dataForm.Data)
  8.     {
  9.         if (item.OwnerTab == moveFromTab.ID)
  10.             item.OwnerTab = moveToTab.ID;
  11.     }
  12. }
  13.  
  14. protected T FindControl<T>(Control control, string id) where T : Control
  15. {
  16.     T controlTest = control as T;
  17.     if (null != controlTest && (null == id || id.Equals(controlTest.ID)))
  18.         return controlTest;
  19.     foreach (Control c in control.Controls)
  20.     {
  21.         controlTest = FindControl<T>(c, id);
  22.         if (null != controlTest)
  23.             return controlTest;
  24.     }
  25.     return null;
  26. }

It’s also possible to change the built in property to another property type, but you have to create a new PropertyDataCollection and assign it to the Data property since that will change the collection.

Jun 22, 2011

Comments

Jun 22, 2011 09:14 PM

That's pretty neat!

Sayeed Choudhury
Sayeed Choudhury Jan 16, 2014 03:27 PM

How do I make a built-in property like VisibleInMenu or SortOrder to be [CultureSpecific]??

Please login to comment.
Latest blogs
Optimizely Forms: You cannot submit this form because an administrator has turned off data storage.

Do not let this error message scare you, the solution is quite simple!

Tomas Hensrud Gulla | Oct 4, 2024 | Syndicated blog

Add your own tools to the Optimizely CMS 12 admin menu

The menus in Optimizely CMS can be extended using a MenuProvider, and using the path parameter you decide what menu you want to add additional menu...

Tomas Hensrud Gulla | Oct 3, 2024 | Syndicated blog

Integrating Optimizely DAM with Your Website

This article is the second in a series about integrating Optimizely DAM with websites. It discusses how to install the necessary package and code t...

Andrew Markham | Sep 28, 2024 | Syndicated blog

Opticon 2024 - highlights

I went to Opticon in Stockholm and here are my brief highlights based on the demos, presentations and roadmaps  Optimizely CMS SaaS will start to...

Daniel Ovaska | Sep 27, 2024