Sha256: b6ddf262ea88143b12fe3206cbdcaabe3bf34fe11a7d539480326c5a83b9386e

Contents?: true

Size: 1.44 KB

Versions: 28

Compression:

Stored size: 1.44 KB

Contents

module CamaleonCms::HooksHelper
  include CamaleonCms::PluginsHelper
  
  # 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).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
        Rails.logger.debug "Camaleon CMS - Hook \"#{hook_key}\" executed from dependency #{plugin['key'] rescue ''}".cama_log_style(:light_blue)
      rescue
        plugin_load_helpers(plugin)
        if params.nil?
          send(hook)
        else
          send(hook, params)
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
camaleon_cms-2.4.5.5 app/helpers/camaleon_cms/hooks_helper.rb
camaleon_cms-2.4.5.4 app/helpers/camaleon_cms/hooks_helper.rb
camaleon_cms-2.4.5.3 app/helpers/camaleon_cms/hooks_helper.rb
camaleon_cms-2.4.5.2 app/helpers/camaleon_cms/hooks_helper.rb
camaleon_cms-2.4.5.1 app/helpers/camaleon_cms/hooks_helper.rb
camaleon_cms-2.4.5 app/helpers/camaleon_cms/hooks_helper.rb
camaleon_cms-2.4.4.7 app/helpers/camaleon_cms/hooks_helper.rb
camaleon_cms-2.4.4.6 app/helpers/camaleon_cms/hooks_helper.rb
camaleon_cms-2.4.4.5 app/helpers/camaleon_cms/hooks_helper.rb
camaleon_cms-2.4.4.4 app/helpers/camaleon_cms/hooks_helper.rb
camaleon_cms-2.4.4.3 app/helpers/camaleon_cms/hooks_helper.rb
camaleon_cms-2.4.4.2 app/helpers/camaleon_cms/hooks_helper.rb
camaleon_cms-2.4.4.1 app/helpers/camaleon_cms/hooks_helper.rb
camaleon_cms-2.4.4 app/helpers/camaleon_cms/hooks_helper.rb
camaleon_cms-2.4.3.13 app/helpers/camaleon_cms/hooks_helper.rb
camaleon_cms-2.4.3.12 app/helpers/camaleon_cms/hooks_helper.rb
camaleon_cms-2.4.3.11 app/helpers/camaleon_cms/hooks_helper.rb
camaleon_cms-2.4.3.10 app/helpers/camaleon_cms/hooks_helper.rb
camaleon_cms-2.4.3.9 app/helpers/camaleon_cms/hooks_helper.rb
camaleon_cms-2.4.3.8 app/helpers/camaleon_cms/hooks_helper.rb