SaaS CMS has officially launched! Learn more now.

Logging changes to ContentType Access Level



Is there an event for capturing changes to content type access level? 

Something similar to IContentSecurityRepository ContentSecuritySaved event, but for content types.


Jul 27, 2021 15:21

You can use (i.e. listen to)

ContentTypeRepository.ContentTypeSaved and ContentTypeDeleted 
Jul 28, 2021 8:44
David Chrystal - Jul 28, 2021 12:25
Thanks Quan, unfortunately I wasn't able to hook into the ContentTypeSaved event of the ContentTypeRepository.
Quan Mai - Jul 28, 2021 17:55
Why is that? It does not work or you can't because of some requirements?
Quan Mai - Jul 28, 2021 17:55
Why is that? It does not work or you can't because of some requirements?
Scott Reed - Aug 02, 2021 8:07
I imagine maybe he was trying to do it on the injected IContentSecurityRepository as mentioned in the first post and I tried rather than directly accessing the event on the ContentTypeRepository which was the mistake I made. Although I say my mistake we I think the ContentTypeRepository should be redesigned to work like the other repositories so the events are on the Interface like the IContentEvents as it's easy to miss.
David Chrystal - Aug 02, 2021 8:30
I was loading the content type repository form the interface ServiceLocator.Current.GetInstance
Scott Reed - Aug 02, 2021 8:37
Ah Yes David, the events are static on the ContentTypeRepository itself so it won't work loading the type in via the service locator. You just access directly on the ContentTypeRepository. To be fair if you've got it working the way I said it's groovy just responding to Quan on why I thought it might not be working for you which seems to be the correct assumption. It's a little weirdly designed compared to other services/repositories.

You can hook in to the IActivityEvents event for ActivityCreated and when the Save button is clicked it will trigger and provide info on the changed type.

You may have to figure out some code to detect that it's a change to the ACL but here's at least the start / answer to the event question that hopefully helps

using EPiServer;
using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.DataAbstraction.Activities;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;
using EPiServer.ServiceLocation;

namespace TmxEpi.Ecommerce.Storefront.Site.Infrastructure.Initialization
    public class ContentInitializationModule : IConfigurableModule
        private static IContentTypeRepository _contentTypeRepository;
        private static IActivityEvents _activityEvents;

        public void Initialize(InitializationEngine context)
            _activityEvents = context.Locate.Advanced.GetInstance<IActivityEvents>();
            _contentTypeRepository = context.Locate.Advanced.GetInstance<IContentTypeRepository>();

            _activityEvents.ActivityCreated += _activityEvents_ActivityCreated;

        private void _activityEvents_ActivityCreated(object sender, ActivityCreatedEventArgs e)
            if (e.Activity is ContentTypeActivity contentTypeActivity)
                var contentType = _contentTypeRepository.Load(contentTypeActivity.ContentTypeGuid);
Jul 28, 2021 9:19
Scott Reed - Jul 28, 2021 9:22
Or as quan said the ContentTypeRepository events.
David Chrystal - Jul 28, 2021 12:22
Thanks Scott, that worked.
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.