Itera.Objects, a extension for PageTypeBuilder
I have been looking and PageTypeBuilder, and the concept is great. But one thing I missed was the ability to add objects of all types and not only primitives or propertydata types.
I started by downloading the latest build, and looked around. The Interceptor get’s the value of a property and set’s it on the page object. I therefore had to create a property that was a wrapper around a object. Before I have used Itera.MultiProperty to store many variables. This time I tried to use the dynamic data store, but after a couple of hours trying to set a setting on a property from code I switch over to saving them as real properties on the page.
These properties are disabled from edit mode, and I have a container property that shows these hidden properties.
When Page type builder finds this stuff It will create a 2 properties. But since PTB doesn’t follow type’s I have made a IInitializableModule that follows these types, and adds the hidden properties.
The property PropertyContainer will in a context of a strong Types page create the an instance of the object and populate all the primitives from the hidden property data. If it encounter another PropertyContainer it will create that object and populate it form it’s hidden properties.
There is actually 5 different properties, that will display a bit differently in edit mode.
- PropertyContainer
- PropertyContainerWithHelp
- PropertyContainerSmall
- PropertyContainerSmallNoBox
- PropertyContainerSmallWithHelp
If you specify different tab’s for the different properties the layout will also change.
will display in edit mode like this:
and
How cool is that :)
And even better, the tabs have access rights!
Very cool!
Wow, this is really cool! To bad you did't find a way for using settings for properties via code. Have you talked with EPiServer about it?
Thanks.
I sent a mail to Mr Smith :), but haven't got a replay. The logical step would to bind what kind of type the property should be as an value on the property setting. Instead I needed to find the PageType when you access the Value and find by reflection the type.
It could also be possible to save the inner values inside these property settings, but as it turned out there are a few benifitts of saveing them as real properties. Copy, Export and so on....
/ Anders Hattestad
Seems like a good way to structure your pages into reusable components. Very cool!
/ Patrik Akselsson
Wow, what a great idea and implementation.
This is, from a code perspective rather than a persistence perspective, really beginning to stretch the EPiServer model beyond simple dictionary based PropertyBags.
Probably a big ask, but is there any way to go further and allow strongly typed access to List and Collection types. This will obviously present difficulties unless those collections were serializable, but that functionality would really be valuable.
There is a couple of ways of doing lists.
1) Itera.MultiProperty do save all sub properties as a string. The only issue is that we need a way populating the PageData object with it's value.
2) make a generic PropertyAnyClass class that use the ObjectDataStore. I have actully most of the implementasion ready, will post it as soon I can.
If any of you have managed to set a property setting on property from code, please let me know.
/ Anders Hattestad
What email? I haven't seen anything from you Anders.
/ Paul Smith
Guess it got cought in the crazy laughing programmer mail filter rule you have:)
was basicly a question about some example code for setting a property setting when all you had was the propertie def id
will resend
/ Anders Hattestad
My bad.
Had an error in paul smith's epost adress , so you can stop searching your email server :)
/ Anders Hattestad
Really interesting stuff! Will take a closer look at it as soon as I can. I'm also very interested in your question to Paul, so perhaps you, Paul, could post your reply as a blog post?
Oh and I'd also love to hear more about your experiences of building on top of/plugging into Page Type Builder!
Got an answar to how we should set properties on properties by code.
setting is the propertysetting class.
object setting=Activator.CreateInstance(EPiPropertySetting.PropertySettingType, EPiPropertySetting.PropertySettingArgument);
if (realProperty.SettingsID == Guid.Empty)
{
realProperty.SettingsID = Guid.NewGuid();
realProperty.Save();
}
var settingsContainer = new PropertySettingsContainer(realProperty.SettingsID);
settingsContainer.AddSettings(new PropertySettingsWrapper
{
PropertySettings = setting as IPropertySettings,
DisplayName = EPiPropertySetting.PropertySettingType.Name,
IsGlobal = false,
IsDefault = false
});
new PropertySettingsRepository().Save(settingsContainer);
/ Anders Hattestad
Anders! I removed a property from code, and now it crashes on startup.
Line 221: return (this.ClassAttribute.EditCaption == null ? Name : (this.ClassAttribute.EditCaption+"["+this.Name+"]")) + " (is " + this.ClassPropertyType.Name + " render as " + EPiPropertyType.Name + ")";
in PropertyInfoAndData.cs returns a null reference.
Sorry, that was not the issue.
I added a new property of the type int, but i did not declare a Type=typeof(PropertyNumber) when doing that. It caused a null reference to EPiPropertyType.
I saw your comment on this post, regarding PageTypePropertyGroups in PageTypeBuilder 2: http://world.episerver.com/Blogs/Lee-Crowe/Dates/2011/5/PageTypePropertyGroup-for-PageTypeBuilder-v2/
I am using PageTypePropertyGroups, but I love what you have done here by visually grouping the properties together in edit mode. Nice job! :-)
Do you have a version of your code which works with the new PageTypePropertyGroups in PageTypeBuilder 2?
Hi Bjorn
When PageTypeBuilder 2 is officially released I will release a new version of PageTypeBuilderUI. This will contain functionality similar to what Anders has done with his Itera.Objects project to lay the property group properties out in a nicer format.
Lee