[Question] How to extend a builtin module

2025/07/01 4:37 PM

Hello friends


I would like to add a custom button to an existing module in Xperience by Kentico admin site. Basically, I would like to add a Clear log button under the Event Log module, since it would help us as developers to clear up all the stuff and grant us better visibility when debugging or catching issues in real-time

So, any hint is always welcome!

Thanks in advance

Environment

  • Xperience by Kentico version: 30.6.0

  • .NET version: 8

  • Execution environment: Private cloud (Azure/AWS/Virtual machine)

Tags:
Xperience Administration

Answers

2025/07/01 4:45 PM
Answer

Hey Victor! Extending UI pages can be done with page extenders. I answered this same question pretty recently and wrote up this sample code:

[assembly: PageExtender(typeof(EventLogExtender))]
namespace MySite
{
    public class EventLogExtender(IHttpContextAccessor httpContextAccessor) : PageExtender<EventLogList>
    {
        public override Task ConfigurePage()
        {
            Page.PageConfiguration.HeaderActions.AddCommand("Clear log", nameof(Clear));

            return base.ConfigurePage();
        }

        [PageCommand]
        public async Task<ICommandResponse> Clear()
        {
            var authenticatedUserAccessor = httpContextAccessor.HttpContext.RequestServices.GetRequiredService<IAuthenticatedUserAccessor>();
            var user = await authenticatedUserAccessor.Get();
            EventLogHelper.ClearEventLog(user.UserID, user.UserName, httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString());

            return Response().UseCommand("LoadData").AddSuccessMessage("Event log cleared");
        }
    }
}

This also logs a "Log cleared" event after the button click (like we did in K13) so you can audit who is clearing the Event log. I find that I can usually guess the class that I need to reference in PageExtender<T> but if you're not sure, you can find the backend template in System > UI Tree:

1.00

2025/07/01 5:50 PM

That helps a lot! Thanks Eric for the support!

To answer this question, you have to login first.