Anders Hattestad
Jun 22, 2011
  5297
(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
Opti ID overview

Opti ID allows you to log in once and switch between Optimizely products using Okta, Entra ID, or a local account. You can also manage all your use...

K Khan | Jul 26, 2024

Getting Started with Optimizely SaaS using Next.js Starter App - Extend a component - Part 3

This is the final part of our Optimizely SaaS CMS proof-of-concept (POC) blog series. In this post, we'll dive into extending a component within th...

Raghavendra Murthy | Jul 23, 2024 | Syndicated blog

Optimizely Graph – Faceting with Geta Categories

Overview As Optimizely Graph (and Content Cloud SaaS) makes its global debut, it is known that there are going to be some bugs and quirks. One of t...

Eric Markson | Jul 22, 2024 | Syndicated blog

Integration Bynder (DAM) with Optimizely

Bynder is a comprehensive digital asset management (DAM) platform that enables businesses to efficiently manage, store, organize, and share their...

Sanjay Kumar | Jul 22, 2024