Sha256: f73fbc5fab2d068d23dd739ca77a24c273ccba2e57aacda1caf2555ee59ee9ab

Contents?: true

Size: 1.24 KB

Versions: 4

Compression:

Stored size: 1.24 KB

Contents

module CamaleonCms::HooksHelper
  # execute hooks for plugin_key with action name hook_key
  # non public method
  # plugin: plugin configuration (config.json)
  # hook_key: hook key
  # params: params for hook
  def hook_run(plugin, hook_key, params = nil)
    _do_hook(plugin, hook_key, params)
  end

  # execute all hooks from enabled plugins with key hook_key
  # non public method
  # hook_key: hook key
  # params: params for hook
  def hooks_run(hook_key, params = nil)
    PluginRoutes.enabled_apps(current_site, current_theme.slug).each do |plugin|
      _do_hook(plugin, hook_key, params)
    end
  end

  # skip hook function with name: hook_function_name
  def hook_skip(hook_function_name)
    @_hooks_skip << hook_function_name
  end

  private

  def _do_hook(plugin, hook_key, params =  nil)
    return if !plugin.present? || !plugin["hooks"].present? || !plugin["hooks"][hook_key].present?

    plugin["hooks"][hook_key].each do |hook|
      next if @_hooks_skip.present? && @_hooks_skip.include?(hook)
      begin
        send(hook, params) unless params.nil?
        send(hook) if params.nil?
      rescue
        plugin_load_helpers(plugin)
        send(hook, params) unless params.nil?
        send(hook) if params.nil?
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
camaleon_cms-2.3.3 app/helpers/camaleon_cms/hooks_helper.rb
camaleon_cms-2.3.2 app/helpers/camaleon_cms/hooks_helper.rb
camaleon_cms-2.3.1 app/helpers/camaleon_cms/hooks_helper.rb
camaleon_cms-2.3.0 app/helpers/camaleon_cms/hooks_helper.rb