From 567dd0d2c6a5932d37dedce910b6e60160dcd36d Mon Sep 17 00:00:00 2001 From: Sommerregen Date: Thu, 29 Jan 2015 16:51:17 +0100 Subject: [PATCH] Added merge config and disable function in "Plugin.php" --- system/src/Grav/Common/Plugin.php | 73 +++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/system/src/Grav/Common/Plugin.php b/system/src/Grav/Common/Plugin.php index 6cc46f1a2..f4fb3230d 100644 --- a/system/src/Grav/Common/Plugin.php +++ b/system/src/Grav/Common/Plugin.php @@ -1,6 +1,9 @@ grav['events']; + + foreach ($events as $eventName => $params) { + if (is_string($params)) { + $dispatcher->removeListener($eventName, array($this, $params)); + } elseif (is_string($params[0])) { + $dispatcher->removeListener($eventName, array($this, $params[0])); + } else { + foreach ($params as $listener) { + $dispatcher->removeListener($eventName, array($this, $listener[0])); + } + } + } + } + + /** + * Merge global and page configurations. + * + * @param Page $page The page to merge the configurations with the + * plugin settings. + */ + protected function mergeConfig(Page $page) + { + static $className; + + if ( is_null($className) ) { + // Load configuration based on class name + $reflector = new \ReflectionClass($this); + + // Remove namespace and trailing "Plugin" word + $name = $reflector->getShortName(); + $name = substr($name, 0, -strlen('Plugin')); + + // Guess configuration path from class name + $class_formats = array( + strtolower($name), # all lowercased + Inflector::underscorize($name), # underscored + ); + + $defaults = array(); + // Try to load configuration + foreach ( $class_formats as $name ) { + if ( !is_null($this->config->get('plugins.' . $name, NULL)) ) { + $className = $name; + break; + } + } + } + + // Get default plugin configurations and retrieve page header configuration + $plugin = (array) $this->config->get('plugins.' . $className, array()); + $header = (array) $page->header(); + + // Create new config data class + $config = new Data(); + + // Join configuration options + $config->setDefaults($header); + $config->joinDefaults($className, $plugin); + + // Return configurations as a new data config class + return $config; + } }