You are here

function crumbs_InjectedAPI_Collection_PluginCollection::addPlugin in Crumbs, the Breadcrumbs suite 7.2

Parameters

crumbs_PluginInterface $plugin:

string $plugin_key:

string|null $route:

Throws

Exception

File

lib/InjectedAPI/Collection/PluginCollection.php, line 92

Class

crumbs_InjectedAPI_Collection_PluginCollection

Code

function addPlugin(crumbs_PluginInterface $plugin, $plugin_key, $route = NULL) {
  if (isset($this->plugins[$plugin_key])) {
    throw new Exception("There already is a plugin with key '{$plugin_key}'.");
  }
  if (isset($route)) {
    $legacyMethods = $this
      ->analyzeRoutePluginMethods($route, $plugin_key, $plugin);
  }
  else {
    $legacyMethods = $this
      ->analyzePluginMethods($plugin_key, $plugin);
  }
  if (!empty($legacyMethods)) {
    $legacyMethods += array(
      'findParent' => array(),
      'findTitle' => array(),
    );
    if ($plugin instanceof crumbs_MultiPlugin) {
      $plugin = new crumbs_MultiPlugin_LegacyWrapper($plugin, $legacyMethods['findParent'], $legacyMethods['findTitle']);
    }
    elseif ($plugin instanceof crumbs_MonoPlugin) {
      $plugin = new crumbs_MonoPlugin_LegacyWrapper($plugin, $legacyMethods['findParent'], $legacyMethods['findTitle']);
    }
  }
  $this->plugins[$plugin_key] = $plugin;
}