You are here

function crumbs_InjectedAPI_hookCrumbsPlugins::multiPlugin in Crumbs, the Breadcrumbs suite 7

Same name and namespace in other branches
  1. 7.2 lib/InjectedAPI/hookCrumbsPlugins.php \crumbs_InjectedAPI_hookCrumbsPlugins::multiPlugin()

Register a "Multi" plugin. That is, a plugin that defines more than one rule.

Parameters

$key: Rule key, relative to module name.

$plugin: Plugin object. Needs to implement crumbs_MultiPlugin. Or NULL, to have the plugin object automatically created based on a class name guessed from the $key parameter and the module name.

File

lib/InjectedAPI/hookCrumbsPlugins.php, line 84

Class

crumbs_InjectedAPI_hookCrumbsPlugins
API object to be used as an argument for hook_crumbs_plugins() This is a sandbox class, currently not used..

Code

function multiPlugin($key, $plugin = NULL) {
  if (!isset($key)) {
    $class = $this->module . '_CrumbsMultiPlugin';
    $plugin = new $class();
    $plugin_key = $this->module;
  }
  elseif (!isset($plugin)) {
    $class = $this->module . '_CrumbsMultiPlugin_' . $key;
    $plugin = new $class();
    $plugin_key = $this->module . '.' . $key;
  }
  else {
    $class = get_class($plugin);
    $plugin_key = $this->module . '.' . $key;
  }
  if (!$plugin instanceof crumbs_MultiPlugin) {
    throw new Exception("{$class} must implement class_MultiPlugin.");
  }
  $this->plugins[$plugin_key] = $plugin;
  if (method_exists($plugin, 'disabledByDefault')) {
    $disabled_by_default = $plugin
      ->disabledByDefault();
    if ($disabled_by_default !== NULL) {
      if (!is_array($disabled_by_default)) {
        throw new Exception("{$class}::disabledByDefault() must return an array or NULL.");
      }
      foreach ($disabled_by_default as $suffix) {
        if (!isset($suffix) || $suffix === '') {
          throw new Exception("{$class}::disabledByDefault() - returned array contains an empty key.");
        }
        else {
          $key = $plugin_key . '.' . $suffix;
          $disabled_keys[$key] = $key;
        }
      }
    }
  }
}