From e257d7d6d4d0899262ed893f8042dd762ee13bf4 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 23 Feb 2012 17:34:17 +0100 Subject: [PATCH] New: possibility to defined hooks in array format with parts module system --- dev/skeletons/modMyModule.class.php | 17 ++++++++++------- htdocs/core/class/conf.class.php | 5 ++++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/dev/skeletons/modMyModule.class.php b/dev/skeletons/modMyModule.class.php index 06a1e79692f..b9bb2d86322 100644 --- a/dev/skeletons/modMyModule.class.php +++ b/dev/skeletons/modMyModule.class.php @@ -68,14 +68,18 @@ class modMyModule extends DolibarrModules // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module' $this->picto='generic'; - // Defined all module parts (triggers, login, substitutions, menus, css, etc...) (0=disable,1=enable default path, '/mymodule/path/to/parts' for specific path) - $this->module_parts = array(); + // Defined all module parts (triggers, login, substitutions, menus, css, etc...) + // for default path (eg: /mymodule/core/triggers) (0=disable, 1=enable) + // for specific path of parts (eg: /core/modules/barcode) + // for specific css file (eg: /css/mymodule.css.php) //$this->module_parts = array( 'triggers' => 1, // 'login' => 0, - // 'substitutions' => '/specific/path/in/your/module', - // 'menus' => 0 - // 'css' => '/css/mymodule.css.php' - // 'barcode => /path/to/your/parts'); + // 'substitutions' => 0, + // 'menus' => 0, + // 'css' => '/css/mymodule.css.php', + // 'barcode' => '/path/to/your/parts', + // 'hooks' => array('hookcontext1','hookcontext2')); + $this->module_parts = array(); // Data directories to create when module is enabled. // Example: this->dirs = array("/mymodule/temp"); @@ -99,7 +103,6 @@ class modMyModule extends DolibarrModules // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive) // Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',1), // 1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0) - // 2=>array('MAIN_MODULE_MYMODULE_HOOKS','chaine','hookcontext1:hookcontext2','To say: This module manage hooks in hookcontext1 and hookcontext2',1,'current',1) // ); $this->const = array(); diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index 6e757c9d7da..92aa90c71ef 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -156,6 +156,7 @@ class Conf $this->tabs_modules[$params[0]][]=$value; } // If this is constant for hook activated by a module. Value is list of hooked tabs separated with ':' + // TODO obsolete (see generic parts) elseif (preg_match('/^MAIN_MODULE_([A-Z_]+)_HOOKS$/i',$key,$reg)) { $modulename = strtolower($reg[1]); @@ -184,7 +185,9 @@ class Conf $modulename = strtolower($reg[1]); $partname = strtolower($reg[2]); $varname = $partname.'_modules'; - $value = ($value === 1 ? '/'.$modulename.'/core/'.$partname.'/' : '/'.$modulename.'/'.$value); + $arrValue = unserialize($value); + if (is_array($arrValue) && ! empty($arrValue)) $value = $arrValue; + else $value = ($value === 1 ? '/'.$modulename.'/core/'.$partname.'/' : '/'.$modulename.'/'.$value); $this->$varname = array_merge($this->$varname, array($modulename => $value)); }