Sha256: fdbe27f8d8262401d61f568a5afc9cb62cf8170a5f5ae7a016efe35efc44ce55

Contents?: true

Size: 1.28 KB

Versions: 3

Compression:

Stored size: 1.28 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
        if params.nil?
          send(hook)
        else
          send(hook, params)
        end
      rescue
        plugin_load_helpers(plugin)
        if params.nil?
          send(hook)
        else
          send(hook, params)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
camaleon_cms-2.3.6 app/helpers/camaleon_cms/hooks_helper.rb
camaleon_cms-2.3.5 app/helpers/camaleon_cms/hooks_helper.rb
camaleon_cms-2.3.4 app/helpers/camaleon_cms/hooks_helper.rb