From b270e19e9171d14e2d6782a658445787f6fd0fb4 Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Wed, 25 Jan 2017 11:50:06 +0100 Subject: [PATCH] Add usage of *_item_form hooks --- inc/itemform.class.php | 120 +++++++++++++++++++++++++++++++++++++++++ setup.php | 11 ++-- 2 files changed, 127 insertions(+), 4 deletions(-) create mode 100644 inc/itemform.class.php diff --git a/inc/itemform.class.php b/inc/itemform.class.php new file mode 100644 index 0000000..77dcaa7 --- /dev/null +++ b/inc/itemform.class.php @@ -0,0 +1,120 @@ +. +-------------------------------------------------------------------------- + */ + +/** + * Summary of PluginExampleItemForm + * Example of *_item_form implementation + * @see http://glpi-developer-documentation.rtfd.io/en/master/plugins/hooks.html#items-display-related + * */ +class PluginExampleItemForm { + + /** + * Display contents at the begining of item forms. + * + * @param array $params Array with "item" and "options" keys + * + * @return void + */ + static public function preItemForm($params) { + $item = $params['item']; + $options = $params['options']; + + $firstelt = ($item::getType() == Ticket::getType() ? 'th' : 'td'); + + $out = ''; + $out .= sprintf( + __('Start %1$s hook call for %2$s type'), + 'pre_item_form', + $item::getType() + ); + $out .= ''; + + $out .= "<$firstelt>"; + $out .= ''; + $out .= ""; + $out .= ''; + $out .= "<$firstelt>"; + $out .= ''; + $out .= ""; + $out .= ''; + $out .= ''; + + $out .= ''; + $out .= sprintf( + __('End %1$s hook call for %2$s type'), + 'pre_item_form', + $item::getType() + ); + $out .= ''; + + echo $out; + } + + /** + * Display contents at the begining of item forms. + * + * @param array $params Array with "item" and "options" keys + * + * @return void + */ + static public function postItemForm($params) { + $item = $params['item']; + $options = $params['options']; + + $firstelt = ($item::getType() == Ticket::getType() ? 'th' : 'td'); + + $out = ''; + $out .= sprintf( + __('Start %1$s hook call for %2$s type'), + 'post_item_form', + $item::getType() + ); + $out .= ''; + + $out .= "<$firstelt>"; + $out .= ''; + $out .= ""; + $out .= ''; + $out .= "<$firstelt>"; + $out .= ''; + $out .= ""; + $out .= ''; + $out .= ''; + + $out .= ''; + $out .= sprintf( + __('End %1$s hook call for %2$s type'), + 'post_item_form', + $item::getType() + ); + $out .= ''; + + echo $out; + } +} diff --git a/setup.php b/setup.php index ffb81f8..133663c 100755 --- a/setup.php +++ b/setup.php @@ -186,10 +186,13 @@ function plugin_init_example() { // pre_show and post_show for tabs and items, // see PluginExampleShowtabitem class for implementation explanations - $PLUGIN_HOOKS['pre_show_tab']['example'] = array( 'PluginExampleShowtabitem', 'pre_show_tab' ); - $PLUGIN_HOOKS['post_show_tab']['example'] = array( 'PluginExampleShowtabitem', 'post_show_tab' ); - $PLUGIN_HOOKS['pre_show_item']['example'] = array( 'PluginExampleShowtabitem', 'pre_show_item' ); - $PLUGIN_HOOKS['post_show_item']['example'] = array( 'PluginExampleShowtabitem', 'post_show_item' ); + $PLUGIN_HOOKS['pre_show_tab']['example'] = array('PluginExampleShowtabitem', 'pre_show_tab'); + $PLUGIN_HOOKS['post_show_tab']['example'] = array('PluginExampleShowtabitem', 'post_show_tab'); + $PLUGIN_HOOKS['pre_show_item']['example'] = array('PluginExampleShowtabitem', 'pre_show_item'); + $PLUGIN_HOOKS['post_show_item']['example'] = array('PluginExampleShowtabitem', 'post_show_item'); + + $PLUGIN_HOOKS['pre_item_form']['example'] = ['PluginExampleItemForm', 'preItemForm']; + $PLUGIN_HOOKS['post_item_form']['example'] = ['PluginExampleItemForm', 'postItemForm']; // declare this plugin as an import plugin for Computer itemtype $PLUGIN_HOOKS['import_item']['exemple'] = array('Computer' => array('Plugin'));