This project is read-only.
Core events are a relatively recent (i.e. 0.4.2) feature to MrCMS. They allow developers to wire into the ISession's Save, Update and Delete operations to perform any actions that should be performed at the time of the database being updated.

An example of this might be when you want to create a media category to be associated to a page when it's initially saved.

To do this you would create an implementation of IOnAdding<YourPageType>. This can then use the standard Ninject IoC to inject dependencies and perform needs to be done.

Example from Ecommerce implementation
        public void Execute(OnAddingArgs<Product> args)
        {
            var product = args.Item;
           
            var mediaCategory = _documentService.GetDocumentByUrl<MediaCategory>("product-galleries");
            if (mediaCategory == null)
            {
                mediaCategory = new MediaCategory
                {
                    Name = "Product Galleries",
                    UrlSegment = "product-galleries",
                    IsGallery = true,
                    HideInAdminNav = true
                };
                _documentService.AddDocument(mediaCategory);
            }
            var productGallery = new MediaCategory
            {
                Name = product.Name,
                UrlSegment = "product-galleries/" + product.UrlSegment,
                IsGallery = true,
                Parent = mediaCategory,
                HideInAdminNav = true
            };
            product.Gallery = productGallery;

            _documentService.AddDocument(productGallery);
        }


With this in place, a gallery will be created for any added product, unless the event is specifically disabled

Last edited Nov 14, 2014 at 2:20 PM by gmstr, version 2

Comments

No comments yet.