Skip to content

Commit

Permalink
#48 - add content containing form to event args
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenn Jacobsen committed Aug 1, 2016
1 parent c08e562 commit ac3d595
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
13 changes: 10 additions & 3 deletions Source/Solution/FormEditor/Events/FormEditorCancelEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
using System.Collections.Generic;
using System.ComponentModel;
using FormEditor.Fields;
using System.ComponentModel;
using Umbraco.Core.Models;

namespace FormEditor.Events
{
public class FormEditorCancelEventArgs : CancelEventArgs
{
public FormEditorCancelEventArgs(IPublishedContent content)
{
Content = content;
}

// if Cancel is set to true, use this property to describe the error to the user
public string ErrorMessage { get; set; }

// the content that contains the form
public IPublishedContent Content { get; private set; }
}
}
7 changes: 6 additions & 1 deletion Source/Solution/FormEditor/Events/FormEditorEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
using System;
using Umbraco.Core.Models;

namespace FormEditor.Events
{
public class FormEditorEventArgs : EventArgs
{
public FormEditorEventArgs(Guid rowId)
public FormEditorEventArgs(Guid rowId, IPublishedContent content)
{
RowId = rowId;
Content = content;
}

// the ID of the persisted data in the storage index
public Guid RowId { get; private set; }

// the content that contains the form
public IPublishedContent Content { get; private set; }
}
}
12 changes: 6 additions & 6 deletions Source/Solution/FormEditor/FormModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public bool CollectSubmittedValues(IPublishedContent content, bool redirect = tr
}

// we're about to add data to the index - let's run the before add to index event handler
var beforeAddToIndexErrorMessage = RaiseBeforeAddToIndex();
var beforeAddToIndexErrorMessage = RaiseBeforeAddToIndex(content);
if(beforeAddToIndexErrorMessage != null)
{
// the event was cancelled - use the validation system to pass the error message back to the user
Expand All @@ -164,7 +164,7 @@ public bool CollectSubmittedValues(IPublishedContent content, bool redirect = tr
}

// tell everyone that something was added
RaiseAfterAddToIndex(rowId);
RaiseAfterAddToIndex(rowId, content);

SetFormSubmittedCookie(content);

Expand Down Expand Up @@ -446,13 +446,13 @@ private string FormatForIndexAndSanitize(FieldWithValue field, IPublishedContent
return doc.DocumentNode.InnerText;
}

private string RaiseBeforeAddToIndex()
private string RaiseBeforeAddToIndex(IPublishedContent content)
{
if(BeforeAddToIndex != null)
{
try
{
var cancelEventArgs = new FormEditorCancelEventArgs();
var cancelEventArgs = new FormEditorCancelEventArgs(content);
BeforeAddToIndex.Invoke(this, cancelEventArgs);
if(cancelEventArgs.Cancel)
{
Expand All @@ -469,13 +469,13 @@ private string RaiseBeforeAddToIndex()
return null;
}

private void RaiseAfterAddToIndex(Guid rowId)
private void RaiseAfterAddToIndex(Guid rowId, IPublishedContent content)
{
if(AfterAddToIndex != null)
{
try
{
AfterAddToIndex.Invoke(this, new FormEditorEventArgs(rowId));
AfterAddToIndex.Invoke(this, new FormEditorEventArgs(rowId, content));
}
catch(Exception ex)
{
Expand Down

0 comments on commit ac3d595

Please sign in to comment.