Is there a hook when adding a new Part to a content type?

Topics: Administration, Core, Customizing Orchard, General, Writing modules
Aug 8, 2012 at 12:43 PM

Hi

I'd like to be able to run something on each content item of a type each time a part is added to that content type. Is there a hook to do this?

Aug 8, 2012 at 5:00 PM

You might be able to implement/inject your own IContentDefinitionService implementation to hook AddPartToType

 

Aug 10, 2012 at 5:18 PM

I've done the following. Should I be concerned about upgrades?

 

namespace Webmoco.QueryFilters.Services
{
    [OrchardSuppressDependency("Orchard.ContentTypes.Services.ContentDefinitionService")]
    public class WebmocoContentDefinitionService : IContentDefinitionService
    {
        private readonly IContentDefinitionService _orchardContentDefinitionService;
        private readonly IContentManager _contentManager;

        public WebmocoContentDefinitionService(IWorkContextAccessor workContextAccessor)
        {
            var services = workContextAccessor.GetContext().Resolve<IOrchardServices>();
            var contentDefinitionManager = workContextAccessor.GetContext().Resolve<IContentDefinitionManager>();
            var contentPartDrivers = workContextAccessor.GetContext().Resolve<IEnumerable<IContentPartDriver>>();
            var contentFieldDrivers = workContextAccessor.GetContext().Resolve<IEnumerable<IContentFieldDriver>>();
            var contentDefinitionEditorEvents =
                workContextAccessor.GetContext().Resolve<IContentDefinitionEditorEvents>();

            _orchardContentDefinitionService = new Orchard.ContentTypes.Services.ContentDefinitionService(services,
                contentDefinitionManager, contentPartDrivers, contentFieldDrivers, contentDefinitionEditorEvents);

            _contentManager = workContextAccessor.GetContext().Resolve<IContentManager>();
        }
        public IEnumerable<EditTypeViewModel> GetTypes()
        {
            return _orchardContentDefinitionService.GetTypes();
        }
     }

etc

Coordinator
Aug 28, 2012 at 6:15 AM

Yes, probably.