Lee Crowe
Nov 4, 2011
  4888
(1 votes)

ElencySolutions.MultipleProperty v1.3.1 Released

For those of you who are not using ElencySolutions.MultipleProperty in their projects please refer back to previous blog posts and the usage instructions linked to on codeplex to see how it could help you out.

Some of the things it allows you to easily do but by no means all are briefly summarised below:

  • Create custom properties that comprise of other properties.
  • Create lists of properties
  • As the Multiple property entities make use of PropertyData objects you are able to pretty much have lists within lists.
  • Ability to define minimum and maximum number of entities.
  • Ability to copy the property to another page.
  • Ability to display entity properties in different tabs.

What’s new in v1.3.1

Those of you who keep an eye on World will probably be wondering why I have released another version already considering I released v1.3 two days ago.

Well, it’s not because there were bugs in v1.3 (as far as I am aware).  It’s because one of my colleagues wanted to do some additional things with property settings which the previous versions didn’t offer.  More specifically she had a property which was essentially a list of FilteredPageReference properties and she wanted to use the list based property on various page types but wanted to restrict the page types that could be picked differently depending on the page type.  She wanted to do this by modifying the filtered page reference settings for the page type property through admin mode..

So as I have plenty of time on the train, I thought I would extend the MultipleProperty offering to cater for her needs and as we are using the FilteredPageReference and MultipleProperty properties more and more I thought it would prove quite useful.

New features are summarised below:

  • A minimum number of entities can now be defined on a list of entities.  If the number of minimum enters have not been added then the page will not be able to be saved.
  • There are now three ways of setting property settings on an entity property.  Well if we are being picky two of them are pretty much the same but I wanted the solution to be backwards compatible.

Installation and Setup

ElencySolutions.MultipleProperty has been built to work with EPiServer CMS 6 and onwards.  Advanced usage instructions (which are definately worth having a read of) as well as examples can be found on codeplex.  The usage instructions also has an FAQ section which could prove quite handy.

The easiest way to install the assembly is to download the latest nuget feed from nuget.episerver.com.

The site on codeplex will also provide useful links for all blog posts that have been posted related to ElencySolutionsMultipleProperty.

Making use of MultipleProperty Entity PropertyData property settings

You are able to define property settings for a Property Control by setting the PropertySettingsCreator property within the MultiplePropertyEntityProperty attribute class.

The value of this property needs to be a type that implements IMultiplePropertySettingsCreator or IMultiplePropertySettingsCreatorAdvanced.

You are now also able to set the UseMatchingSettingsDecoratedOnPropertyType boolean property within the MultiplePropertyEntityProperty attribute class. If the value of the property is set to true then the relevant settings if found will be taken from the ones defined on the physical page type page definition property.

Code Examples

The code below demonstrate how to define property settings for a PropertyHtmlString property using both the IMultiplePropertySettingsCreator and IMultiplePropertySettingsCreatorAdvanced interfaces.

You will notice that for the WYSIWYGAlternative property it uses a property settings creator based on IMultipleSettingsCreatorAdvanced.  This is a new interface for v1.3.1 and the implementation needs to have a method named CreatePropertySettings which accepts a page type id and property name parameter.  This method allows you to conditionally based on the parameters create or load different property settings.  You will also notice that the implementation of this method calls MultiplePropertyHelper.GetPropertySettings which allows you to retrieve property setting that have been defined on a property data instance of a page data object created from a specific page type.

  1: [Serializable]
  2: [DataContract]
  3: [KnownType(typeof(CustomProperty))]
  4: [MultiplePropertyEntity]
  5: public class CustomProperty
  6: {
  7:     public override string ToString()
  8:     {
  9:         return MultiplePropertyHelper.SerializeObject(this);
 10:     }
 11: 
 12:     [MultiplePropertyEntityProperty(Caption = "What you see is what you get",
 13:         Type = typeof(PropertyXhtmlString),
 14:         SortIndex = 100,
 15:         PropertySettingsCreator = typeof(WYSIWYGPropertySettingsCreator))]
 16:     [DataMember]
 17:     public string WYSIWYG { get; set; }
 18: 
 19:     [MultiplePropertyEntityProperty(Caption = "What you see is what you get alternative",
 20:         Type = typeof(PropertyXhtmlString),
 21:         SortIndex = 100,
 22:         PropertySettingsCreator = typeof(WYSIWYGPropertySettingsCreatorAdvanced))]
 23:     [DataMember]
 24:     public string WYSIWYGAlternative { get; set; }
 25: }
 26: 
 27: public class WYSIWYGPropertySettingsCreator : IMultiplePropertySettingsCreator
 28: {
 29:     public IPropertySettings CreatePropertySettings()
 30:     {
 31:         TinyMCESettings settings = new TinyMCESettings().GetDefaultValues() as TinyMCESettings;
 32:         settings.ToolbarRows.Clear();
 33:         return settings;
 34:     }
 35: }
 36: 
 37: public class WYSIWYGPropertySettingsCreatorAdvanced : IMultiplePropertySettingsCreatorAdvanced
 38: {
 39:     public IPropertySettings CreatePropertySettings(int pageTypeId, string propertyName)
 40:     {
 41:         TinyMCESettings settings = new TinyMCESettings().GetDefaultValues() as TinyMCESettings;
 42: 
 43:         if (pageTypeId == 33 && string.Equals(propertyName, "MyCustomProperty_WYWIWYG"))
 44:         {
 45:             settings.ToolbarRows.Clear();
 46:         }
 47:         else if (pageTypeId == 34 && string.Equals(propertyName, "MyCustomProperty_WYWIWYG2"))
 48:         {
 49:             // get the settings from a property defined on a page type
 50:             PageData settingsPage = DataFactory.Instance.GetChildren(PageReference.RootPage)
 51:                 .Where(current => string.Equals(current.PageTypeName, "Settings Page Type"))
 52:                 .FirstOrDefault();
 53: 
 54:             if (settingsPage != null)
 55:                 settings = (TinyMCESettings)MultiplePropertyHelper.GetPropertySettings(settingsPage.Property["SomeProperty"], typeof(TinyMCESettings));
 56:         }
 57: 
 58:         return settings;
 59:     }
 60: }

The following example will demonstrate how you could make use of settings that have been applied to a property definition belonging to a page type and edited through admin mode.

You will notice that the UseMatchingSettingsDecoratedOnPropertyType boolean property of the MultiplePropertyEntityPropertyAttribute is set to true. 

In this example as the property control is a PropertyXhtmlString the code will look for TincyMCESettings that have been set on the property definition and if there are any it will apply the to the entity property.

  1: [Serializable]
  2: [PageDefinitionTypePlugIn(DisplayName = "PropertyCustomPropertyTwo", Description = "A custom property")]
  3: [PropertySettings(typeof(TinyMCESettings), true)]
  4: public class PropertyCustomPropertyTwo: MultiplePropertyBase<CustomPropertyTwo, CustomPropertyTwo>
  5: {
  6:     public override void CreateDefaultViewControls(Web.PropertyControls.PropertyDataControl control)
  7:     {
  8:         if (Value == null)
  9:             return;
 10: 
 11:         Gallery galleryControl = control.Page.LoadControl("~/MultiplePropertyExample/Units/Gallery.ascx") as Gallery;
 12:         galleryControl.PopulateControl(Value as ImageGallery);
 13:         control.Controls.Add(galleryControl);
 14:     }
 15: }
 16: 
 17: [Serializable]
 18: [DataContract]
 19: [KnownType(typeof(CustomPropertyTwo))]
 20: [MultiplePropertyEntity]
 21: public class CustomPropertyTwo
 22: {
 23:     public override string ToString()
 24:     {
 25:         return MultiplePropertyHelper.SerializeObject(this);
 26:     }
 27: 
 28:     [MultiplePropertyEntityProperty(Caption = "What you see is what you get",
 29:         Type = typeof(PropertyXhtmlString),
 30:         SortIndex = 100,
 31:         UseMatchingSettingsDecoratedOnPropertyType = true)]
 32:     [DataMember]
 33:     public string WYSIWYG { get; set; }
 34: }

 

Feedback

As always feedback is greatly appreciated, how many people are actively using this project within there EPiServer 6 solutions?

Also, if you have any suggestions for new features or changes I am happy to hear them.

Just twitter me @croweman or send me an email Smile

Nov 04, 2011

Comments

Please login to comment.
Latest blogs
Copy Optimizely SaaS CMS Settings to ENV Format Via Bookmarklet

Do you work with multiple Optimizely SaaS CMS instances? Use a bookmarklet to automatically copy them to your clipboard, ready to paste into your e...

Daniel Isaacs | Dec 22, 2024 | Syndicated blog

Increase timeout for long running SQL queries using SQL addon

Learn how to increase the timeout for long running SQL queries using the SQL addon.

Tomas Hensrud Gulla | Dec 20, 2024 | Syndicated blog

Overriding the help text for the Name property in Optimizely CMS

I recently received a question about how to override the Help text for the built-in Name property in Optimizely CMS, so I decided to document my...

Tomas Hensrud Gulla | Dec 20, 2024 | Syndicated blog

Resize Images on the Fly with Optimizely DXP's New CDN Feature

With the latest release, you can now resize images on demand using the Content Delivery Network (CDN). This means no more storing multiple versions...

Satata Satez | Dec 19, 2024

Simplify Optimizely CMS Configuration with JSON Schema

Optimizely CMS is a powerful and versatile platform for content management, offering extensive configuration options that allow developers to...

Hieu Nguyen | Dec 19, 2024

Useful Optimizely CMS Web Components

A list of useful Optimizely CMS components that can be used in add-ons.

Bartosz Sekula | Dec 18, 2024 | Syndicated blog