Try our conversational search powered by Generative AI!

Anders Hattestad
Jun 22, 2011
  5264
(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
Solving the mystery of high memory usage

Sometimes, my work is easy, the problem could be resolved with one look (when I’m lucky enough to look at where it needs to be looked, just like th...

Quan Mai | Apr 22, 2024 | Syndicated blog

Search & Navigation reporting improvements

From version 16.1.0 there are some updates on the statistics pages: Add pagination to search phrase list Allows choosing a custom date range to get...

Phong | Apr 22, 2024

Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog