November Happy Hour will be moved to Thursday December 5th.

Anders Hattestad
Jun 22, 2011
  5343
(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 SaaS CMS + Coveo Search Page

Short on time but need a listing feature with filters, pagination, and sorting? Create a fully functional Coveo-powered search page driven by data...

Damian Smutek | Nov 21, 2024 | Syndicated blog

Optimizely SaaS CMS DAM Picker (Interim)

Simplify your Optimizely SaaS CMS workflow with the Interim DAM Picker Chrome extension. Seamlessly integrate your DAM system, streamlining asset...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Optimizely CMS Roadmap

Explore Optimizely CMS's latest roadmap, packed with developer-focused updates. From SaaS speed to Visual Builder enhancements, developer tooling...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Set Default Culture in Optimizely CMS 12

Take control over culture-specific operations like date and time formatting.

Tomas Hensrud Gulla | Nov 15, 2024 | Syndicated blog

I'm running Optimizely CMS on .NET 9!

It works 🎉

Tomas Hensrud Gulla | Nov 12, 2024 | Syndicated blog

Recraft's image generation with AI-Assistant for Optimizely

Recraft V3 model is outperforming all other models in the image generation space and we are happy to share: Recraft's new model is now available fo...

Luc Gosso (MVP) | Nov 8, 2024 | Syndicated blog