Last active
August 29, 2015 14:12
-
-
Save azturner/59620d17576aa03290a6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Web.UI.WebControls; | |
using Rock; | |
using Rock.Field.Types; | |
using Rock.Web.Cache; | |
namespace org.rockchurch.SampleProject.Field.Types | |
{ | |
class DefinedValueByDescriptionFieldType : DefinedValueFieldType | |
{ | |
public override string FormatValue( System.Web.UI.Control parentControl, string value, Dictionary<string, Rock.Field.ConfigurationValue> configurationValues, bool condensed ) | |
{ | |
string formattedValue = string.Empty; | |
if ( !string.IsNullOrWhiteSpace( value ) ) | |
{ | |
var names = new List<string>(); | |
foreach ( string guidValue in value.Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries ) ) | |
{ | |
var definedValue = Rock.Web.Cache.DefinedValueCache.Read( guidValue.AsGuid() ); | |
if ( definedValue != null ) | |
{ | |
names.Add( condensed ? definedValue.Value : definedValue.Description ); | |
} | |
} | |
formattedValue = names.AsDelimited( ", " ); | |
} | |
return formattedValue; | |
} | |
public override System.Web.UI.Control EditControl( Dictionary<string, Rock.Field.ConfigurationValue> configurationValues, string id ) | |
{ | |
var listControl = base.EditControl( configurationValues, id ) as ListControl; | |
if ( listControl != null ) | |
{ | |
foreach ( ListItem listItem in listControl.Items ) | |
{ | |
var definedValue = DefinedValueCache.Read( listItem.Value.AsInteger() ); | |
if ( definedValue != null ) | |
{ | |
listItem.Text = definedValue.Description; | |
} | |
} | |
} | |
return listControl; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment