System Library Common Episerver
Search Results for

    DocFx,SystemLibrary.Common.Episerver.Properties.MessageConfig,SystemLibrary.Common.Episerver.Properties.MessageEditorDescriptor,SystemLibrary.Common.Episerver.Properties.MessageProperty,SystemLibrary.Common.Episerver.Properties.MessageController,SystemLibrary.Common.Episerver.Attributes.BoxSelectionController,SystemLibrary.Common.Episerver.Attributes.BoxSelectionFactory,SystemLibrary.Common.Episerver.Attributes.JsonEditController,SystemLibrary.Common.Episerver.Attributes.JsonEditFactory,SystemLibrary.Common.Episerver.Descriptors.HideCategoryListDescriptor,SystemLibrary.Common.Episerver.Properties.ParentLinkReferenceController,SystemLibrary.Common.Episerver.Properties.ParentLinkReferenceEditorDescriptor,SystemLibrary.Common.Episerver.Properties.ParentLinkReferenceProperty,SystemLibrary.Common.Episerver.Attributes.MultiDropdownSelectionController,SystemLibrary.Common.Episerver.Attributes.MultiDropdownSelectionFactory,SystemLibrary.Common.Episerver.Initialize.RemoveSuggestedContentTypes,SystemLibrary.Common.Episerver.Extensions.CommonEpiserverApplicationServicesOptions,SystemLibrary.Common.Episerver.Extensions.CommonEpiserverApplicationBuilderOptions,SystemLibrary.Common.Episerver.EditController,SystemLibrary.Common.Episerver.Abstract.BaseController,SystemLibrary.Common.Episerver.Abstract.BaseMultiSelectionFactory,SystemLibrary.Common.Episerver.ConnectionStringsConfig,SystemLibrary.Common.Episerver.PropertiesConfig,SystemLibrary.Common.Episerver.EditConfig,SystemLibrary.Common.Episerver.Properties.MessageConfig,SystemLibrary.Common.Episerver.FontAwesome,SystemLibrary.Common.Episerver.AppSettings.Configuration,SystemLibrary.Common.Episerver.Attributes.ParentLinkReferenceFactory,SystemLibrary.Common.Episerver.Abstract.InternalBaseController,WebApplicationInitializer
    Show / Hide Table of Contents
    NamespaceSystemLibrary.Common.Episerver SystemLibrary.Common.Episerver.dll

    Validator class supports Error, Warning and Information messages displayed upon when editors in the CMS clicks 'Publish'

    - Error messages prevents the content from being published

    - Info and Warning messages does not prevent the content from being published

    Validator<T>

    public abstract class Validator<T> : IValidate<T>, IValidate where T : IContentData

    Inheritance
    System.Object
    Validator<T>
    Implements
    EPiServer.Validation.IValidate<T>
    EPiServer.Validation.IValidate
    Type Parameters
    Name Description
    T
    Examples
    X
    public class StartPage : PageData 
    {
        public virtual XhtmlString Title { get; set; }
    }
    
    public class StartPageValidator : Validator<StartPage>
    {
        public override void OnValidate(StartPage instance) 
        {
            if(!IsValid(instance.Title)) //Inherited method
            {
                Error(nameof(instance.Title)); //Inherited method, has built-in message as: 'Property: must be set'
                Info(nameof(instance.Title)); //Inherited method, has built-in message as: 'Property: should be set'
                Warning(nameof(instance.Title)); //Inherited method, has built-in message as: 'Property: can be set'
    
                //Pass a custom message?
                //Note: the 'Title', property name, will be prefixed with the message automatically, if message does not contain it already
                Error(nameof(instance.Title), "must be between 1-255 chars long");
            }
        }
    }
    Arguments
    X
    Generic types
    Name Description
    T

    Methods

    Display 'red error message' on publishing content

    - This prevents the content from being published

    Default 'message' is set to "must be set"
    Remarks
    X

    Message is prefixed with property name (or its display name if it has the display attribute), unless message contains the prefix value already

    View Source

    public void Error(string propertyName, string message = "must be set")

    X
    public override void OnValidate(StartPage instance) 
    {
        Error(nameof(instance.Title));
    
        //Message is prefixed with property name (or its display name if it has the display attribute), unless message contains the prefix value already
        Error(nameof(instance.Title), "must be between 1-255 chars long");
    }
    X
    Methods arguments
    Type Name Description
    System.String propertyName
    System.String message

    Display 'blue info message' on publishing content

    - This does not prevent the content from being published

    Default 'message' is set to "can be set"
    Remarks
    X

    Message is prefixed with property name (or its display name if it has the display attribute), unless message contains the prefix value already

    View Source

    public void Info(string propertyName, string message = "can be set")

    X
    public override void OnValidate(StartPage instance) 
    {
        Info(nameof(instance.Title));
    
        //Message is prefixed with property name (or its display name if it has the display attribute), unless message contains the prefix value already
        Info(nameof(instance.Title), "must be between 1-255 chars long");
    }
    X
    Methods arguments
    Type Name Description
    System.String propertyName
    System.String message

    Returns true if the value is something, else false

    A quick and simple validation to see that the 'value' is filled out with something, for properties of type:

    string, int, ContentReference, LinkItem, LinkItemCollection, ContentArea, XhtmlString, IList, DateTime, Uri, ContentLink, Url and Enums
    Remarks
    X

    Simple check to validate that input in string, xhtmlstring or similar is something more than a blank

    Simple check to validate that links at least have a href, does not force a title nor a name

    Simple check that content area has at least one item

    Simple check that an IList has at least one item

    View Source

    public bool IsValid(object value)

    X
    Methods arguments
    Type Name Description
    System.Object value
    X
    Type Description
    System.Boolean

    Override the OnValidate method and add validation logic and validation messages

    View Source

    public abstract void OnValidate(T content)

    X
    public class StartPage : PageData 
    {
        public virtual XhtmlString Title { get; set; }
    }
    
    public class StartPageValidator : Validator<StartPage>
    {
        public override void OnValidate(StartPage instance) 
        {
            if(!IsValid(instance.Title))  //Inherited method
            {
                Error(nameof(instance.Title)); //Inherited method
                Info(nameof(instance.Title)); //Inherited method
                Warning(nameof(instance.Title)); //Inherited method
    
                //Pass a custom message?
                //Note: the 'Title', property name, will be prefixed with the message automatically, if message does not contain it already
                Error(nameof(instance.Title), "must be between 1-255 chars long");
            }
        }
    }
    X
    Methods arguments
    Type Name Description
    T content

    Internal method: CMS invokes this

    View Source

    public IEnumerable<ValidationError> Validate(T instance)

    X
    Methods arguments
    Type Name Description
    T instance
    X
    Type Description
    System.Collections.IEnumerable<EPiServer.Validation.ValidationError>

    Display 'orange warning message' on publishing content

    - This does not prevent the content from being published

    Default 'message' is set to "should be set"
    Remarks
    X

    Message is prefixed with property name (or its display name if it has the display attribute), unless message contains the prefix value already

    View Source

    public void Warning(string propertyName, string message = "should be set")

    X
    public override void OnValidate(StartPage instance) 
    {
        Warning(nameof(instance.Title));
    
        //Message is prefixed with property name (or its display name if it has the display attribute), unless message contains the prefix value already
        Warning(nameof(instance.Title), "must be between 1-255 chars long");
    }
    X
    Methods arguments
    Type Name Description
    System.String propertyName
    System.String message

    Implements

    EPiServer.Validation.IValidate<T>
    EPiServer.Validation.IValidate

    Extension Methods

    TExtensions.ReactServerSideRender<T>(T, Object, String, Boolean, String, String, String, Boolean, Boolean, Boolean)

    }

    • View Source
    In This Article
    Package: nuget
    Source: github
    Website: System Library Common Episerver