Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kieron McIntyre 108 posts 326 karma points
    Sep 28, 2013 @ 19:13
    Kieron McIntyre
    0

    How do I alter a MediaType via the v6 API services?

    I am trying to create an event handler that can add a property to a MediaType when it is created. I am using the v6 API and I can already do this with a ContentType using the ContentTypeService but I can't find a service for MediaType objects or any means of doing this via the MediaService.

    I have tried putting break points on the MediaService and ContentTypeService to catch the saving of a MediaType but with no luck.

    void MediaService_Saving(IMediaService sender, SaveEventArgs<IMedia> e)
    {
         foreach (var item in e.SavedEntities)
         {
             return;
         }
    }
    

    Or:

    void ContentTypeService_SavingContentType(IContentTypeService sender, 
                                              SaveEventArgs<IContentType> e)
    {
        foreach (var item in e.SavedEntities)
        {
            var dataType = DataTypeService.GetDataTypeDefinitionById(-92);
            item.AddPropertyType(new PropertyType(dataType)
                {
                    Alias = "alias here",
                    Name = "name here",
                });
        }
    }
    

    Where should I be looking? It's not obvious how to manipulate a MediaType from here.

  • Kevin Jump 1867 posts 11859 karma points MVP 4x c-trib
    Sep 29, 2013 @ 10:28
    Kevin Jump
    0

    the ContentTypeService contains the events for capturing MediaType

    ContentTypeService.SavingMediaType += ContentTypeService_SavingMediaType;
    ContentTypeService.SavedMediaType += ContentTypeService_SavedMediaType;
    ContentTypeService.DeletingMediaType += ContentTypeService_DeletingMediaType;
    ContentTypeService.DeletedMediaType += ContentTypeService_DeletedMediaType;
    

    i've just tested them and these events fire in 6.1.5

    the callback then passes IMediaType SaveEventArgs

    void ContentTypeService_SavingContentType(IContentTypeService sender, 
                                              SaveEventArgs<IMediaType> e)
    {
        foreach (var item in e.SavedEntities)
        {
          ...
        }
    }
    
  • Kieron McIntyre 108 posts 326 karma points
    Sep 30, 2013 @ 18:20
    Kieron McIntyre
    0

    Awesome, I didn't noticed the ContentTypeService.SavingMediaType member.

    Many thanks.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies