Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Umbraco Forms - Save the creator / editor of a form #1315

Open
AnnaTornroth-NLTG opened this issue Nov 11, 2024 · 2 comments
Open

Umbraco Forms - Save the creator / editor of a form #1315

AnnaTornroth-NLTG opened this issue Nov 11, 2024 · 2 comments
Labels
state/sprint-candidate We're trying to get this in a sprint at HQ in the next few weeks type/feature

Comments

@AnnaTornroth-NLTG
Copy link

AnnaTornroth-NLTG commented Nov 11, 2024

We have a need from our business at NLTG to see who has created or edited a form.


This item has been added to our backlog AB#46019

@nexwork-percy
Copy link

You could opt to add a RecordSavingNotification handler to fill a [potentially hidden] field on the Form just before saving:

public class FormsComposer : IComposer
{
    /// <summary>
    /// Register event handlers for Umbraco Forms.
    /// <see href="https://docs.umbraco.com/umbraco-forms/developer/extending/adding-an-event-handler" />
    /// </summary>
    /// <param name="builder"></param>
    public void Compose(IUmbracoBuilder builder)
    {
        builder.AddNotificationHandler<RecordSavingNotification, FormRecordSavingNotificationHandler>();
    }
}

public class FormRecordSavingNotificationHandler(IMemberManager MemberManager)
    : INotificationHandler<RecordSavingNotification>
{
    public void Handle(RecordSavingNotification notification)
    {
        Task.Run(async () =>
        {
            var currentMember = await MemberManager.GetCurrentMemberAsync();
            if (currentMember is null)
            {
                return;
            }
            var field = notification.Form.AllFields.FirstOrDefault(x => "fieldAliasCurrentMemberName".Equals(x.Alias));
            if (field is not null)
            {
                field.Values = [member.Name];
            }
        }).Wait();
    }

Perhaps that helps you a bit.

@AndyButland
Copy link

Thanks for the suggestion, but I think what you have above isn't quite right @nexwork-percy. You are using members here, but the OP is interested in users who are creating and editing forms, not members submitting them.

Would be nice to introduce this out of the box, so we have consistency with content and media too. We'll take a look in an upcoming sprint.

@AndyButland AndyButland added type/feature state/sprint-candidate We're trying to get this in a sprint at HQ in the next few weeks labels Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state/sprint-candidate We're trying to get this in a sprint at HQ in the next few weeks type/feature
Projects
None yet
Development

No branches or pull requests

3 participants