Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

For example, in the code below, it defines action Index on controller GoogleAnalytics shall be called on Hook HookName.Head. The controller action would return a View with a piece of script.

Code Block
languagec#
    public class GoogleAnalyticsPlugin : HookBasePlugin
    {
        public const string SettingTrackingID = "GoogleAnalytics_TrackingID";
        private readonly ISettingDictionaryService _settingDictionaryService;
        private readonly IUnitOfWorkAsync _unitOfWorkAsync;
        public GoogleAnalyticsPlugin(
            ISettingDictionaryService settingDictionaryService,
            IUnitOfWorkAsync unitOfWorkAsync)
        {
            _settingDictionaryService = settingDictionaryService;
            _unitOfWorkAsync = unitOfWorkAsync;
            AddRoute(HookName.Head, new RouteValueDictionary
            {
                { "action", "Index" }, 
                { "controller", "GoogleAnalytics" }, 
                { "namespaces", "Plugin.Widget.GoogleAnalytics.Controllers"},
                { "area", null},
                { "hookName", HookName.Head}
            });
       }
	...
	}

Plugin Administration

In most cases, the plugin would need to be configured by user with some specific information. For example, in the GoogleAnalytics plugin, user needs to configure the TrackingID in order to generate the script.

In the Admin Panel, there is a Configure button on each plugin, which will then be redirected to a configuration page on that plugin. It can be done by adding the route to the Configuration hook, as below. It would link the action Configure on the controller GoogleAnalytics.

Code Block
            AddRoute(HookName.Configuration, new RouteValueDictionary {                 
                { "action", "Configure" }, 
                { "controller", "GoogleAnalytics" }, 
                { "namespaces", "Plugin.Widget.GoogleAnalytics.Controllers" }, 
                { "area", null } 
            });
       }
	...
	}

...

 

Plugin Install/Uninstall

...