Rock.Field.Types.PageReferenceFieldType.FormatValue C# (CSharp) Method

FormatValue() public method

Returns the field's current value(s)
public FormatValue ( System parentControl, string value, ConfigurationValue>.Dictionary configurationValues, bool condensed ) : string
parentControl System The parent control.
value string Information about the value
configurationValues ConfigurationValue>.Dictionary The configuration values.
condensed bool Flag indicating if the value should be condensed (i.e. for use in a grid column)
return string
        public override string FormatValue( System.Web.UI.Control parentControl, string value, Dictionary<string, ConfigurationValue> configurationValues, bool condensed )
        {
            if ( !string.IsNullOrWhiteSpace( value ) )
            {
                //// Value is in format "Page.Guid,PageRoute.Guid"
                string[] valuePair = value.Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries );
                if ( valuePair.Length > 0 )
                {
                    Guid? pageGuid = valuePair[0].AsGuidOrNull();
                    if ( pageGuid.HasValue )
                    {
                        var page = Rock.Web.Cache.PageCache.Read( pageGuid.Value );
                        if ( page != null )
                        {
                            if ( valuePair.Length > 1 )
                            {
                                Guid? routeGuid = valuePair[1].AsGuidOrNull();
                                if ( routeGuid.HasValue )
                                {
                                    var route = page.PageRoutes.FirstOrDefault( r => r.Guid.Equals( routeGuid.Value ) );
                                    if ( route != null )
                                    {
                                        return string.Format( "{0} ({1})", page.PageTitle, route.Route );
                                    }
                                }
                            }

                            return page.PageTitle;
                        }
                    }
                }
            }

            return value;
        }