Copied to clipboard

Flag this post as spam?

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


  • Thomas 316 posts 603 karma points c-trib
    Jan 24, 2019 @ 14:56
    Thomas
    0

    Eventhandler for Dictionary items

    Hey,

    it is possible to hint the save event for dictionary items? :)

  • Garðar Þorsteinsson 114 posts 556 karma points
    Jan 24, 2019 @ 15:46
    Garðar Þorsteinsson
    1

    Hi Again :)

    Can do it like this.

            public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
                LocalizationService.SavedDictionaryItem += SavedDictionaryItem;
            }
    
            private void SavedDictionaryItem(ILocalizationService sv, SaveEventArgs<IDictionaryItem> args)
            {
                 // Do magic here
            }
    

    You do this inside of ApplicationEventHandler. https://our.umbraco.com/documentation/reference/events/application-startup

  • Thomas 316 posts 603 karma points c-trib
    Jan 24, 2019 @ 15:58
    Thomas
    0

    Hi Again! :D

    When i'm debugging this. Then i'm not hitting my test, test ?

    class GetDictionaryItems : ApplicationEventHandler
    {
        public new void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            LocalizationService.SavedDictionaryItem += SavedDictionaryItem;
        }
    
        private void SavedDictionaryItem(ILocalizationService sv, SaveEventArgs<IDictionaryItem> args)
        {
            var test = sv;
            var test2 = args;
        }
    }
    
  • Nik 1604 posts 7229 karma points MVP 7x c-trib
    Jan 24, 2019 @ 15:59
    Nik
    0

    Hi Thomas,

    Is your GetDictionaryItems class public? If it's not, I think it might need to be for it to work.

    Thanks

    Nik

  • Thomas 316 posts 603 karma points c-trib
    Jan 24, 2019 @ 16:03
    Thomas
    0

    I just added. But that didn't help..

  • Garðar Þorsteinsson 114 posts 556 karma points
    Jan 24, 2019 @ 19:44
    Garðar Þorsteinsson
    0

    It does not need to be public.

    You can see how I used it in the Dictionary package here:

    https://github.com/Vettvangur/Vettvangur.DictionaryHelper

    Startup File Here: https://github.com/Vettvangur/Vettvangur.DictionaryHelper/blob/master/Startup.cs

Please Sign in or register to post replies

Write your reply to:

Draft