Anders Hattestad
Jun 22, 2011
  5347
(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
Custom form element view in Optimizely CMS 12

Do you want full control over the form element markup? Create your own views!

Tomas Hensrud Gulla | Dec 11, 2024 | Syndicated blog

How to Elevate Your Experimentation - Opticon workshop experience

As a non-expert in the field of experimentation, I’d like to share my feedback on the recent Opticon San Antonio workshop session titled "How to...

David Ortiz | Dec 11, 2024

Persisting a Strawberry Shake GraphQL Client for Optimizely's Content Graph

A recent CMS project used Strawberry Shake to generate an up-to-date C# GraphQL client at each build. But what happens to the build if the GraphQL...

Nicholas Sideras | Dec 11, 2024 | Syndicated blog

Opti ID with Secure Cookies And Third Party AddOns

Opti ID has revolutionised access to the Optimizely One suite and is now the preferred authentication method on all PAAS CMS websites that I build....

Mark Stott | Dec 9, 2024

AsyncHelper can be considered harmful

.NET developers have been in the transition to move from synchronous APIs to asynchronous API. That was boosted a lot by await/async keyword of C#...

Quan Mai | Dec 4, 2024 | Syndicated blog

The search for dictionary key

Recently I helped to chase down a ghost (and you might be surprised to know that I, for most part, spend hours to be a ghostbuster, it could be fun...

Quan Mai | Dec 4, 2024 | Syndicated blog