Skip to content

Instantly share code, notes, and snippets.

@willchis
Created July 26, 2018 21:58
Show Gist options
  • Save willchis/8312ec3b59756d72d289c77ff7538dc9 to your computer and use it in GitHub Desktop.
Save willchis/8312ec3b59756d72d289c77ff7538dc9 to your computer and use it in GitHub Desktop.
namespace Sitecore.Forms.Mvc.Pipelines.Error
{
public class FormatErrorMessage : FormProcessorBase<IFormModel>
{
public override void Process(FormProcessorArgs<IFormModel> args)
{
Assert.ArgumentNotNull((object) args, nameof (args));
IFormModel model = args.Model;
if (model == null)
return;
for (int index = 0; index < model.Failures.Count; ++index)
{
ExecuteResult.Failure failure = model.Failures[index];
Log.Warn("Web Forms for Marketers: an exception '{0}' has occured while trying to execute an action '{1}'.".FormatWith((object) failure.ErrorMessage, (object) failure.FailedAction), (object) this);
if (!model.Failures[index].IsCustom && Sitecore.Form.Core.Configuration.Settings.HideInnerError && !model.Failures[index].IsMessageUnchangeable)
{
Database contextDatabase = StaticSettings.ContextDatabase;
if (contextDatabase != null)
{
Item obj1 = contextDatabase.GetItem(((FormModel) model).Item.ID);
if (obj1 != null)
{
string str = obj1[FormIDs.SaveActionFailedMessage];
if (!string.IsNullOrEmpty(str))
{
failure.ErrorMessage = str;
model.Failures[index] = failure;
return;
}
}
Item obj2 = contextDatabase.GetItem(FormIDs.SubmitErrorId);
if (obj2 != null)
{
string str = obj2["Value"];
if (!string.IsNullOrEmpty(str))
{
failure.ErrorMessage = str;
model.Failures[index] = failure;
return;
}
}
}
failure.ErrorMessage = this.ClientMessage;
model.Failures[index] = failure;
}
}
IEnumerable<ExecuteResult.Failure> source = model.Failures.GroupBy<ExecuteResult.Failure, string>((Func<ExecuteResult.Failure, string>) (f => f.ErrorMessage)).Select<IGrouping<string, ExecuteResult.Failure>, ExecuteResult.Failure>((Func<IGrouping<string, ExecuteResult.Failure>, ExecuteResult.Failure>) (g => g.First<ExecuteResult.Failure>()));
model.Failures = source.ToList<ExecuteResult.Failure>();
}
protected virtual string ClientMessage
{
get
{
return DependenciesManager.ResourceManager.Localize("FAILED_SUBMIT");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment