diff --git a/src/Glpi/ContentTemplates/TemplateDocumentation.php b/src/Glpi/ContentTemplates/TemplateDocumentation.php index f68df134cc2..7e3d10f6d22 100644 --- a/src/Glpi/ContentTemplates/TemplateDocumentation.php +++ b/src/Glpi/ContentTemplates/TemplateDocumentation.php @@ -36,7 +36,9 @@ namespace Glpi\ContentTemplates; use Glpi\ContentTemplates\Parameters\ParametersTypes\ParameterTypeInterface; +use Glpi\Plugin\Hooks; use Glpi\Toolbox\MarkdownBuilder; +use Plugin; /** * Class used to build the twig variable documentation for a given set of @@ -110,6 +112,7 @@ public function addSection( ) { // Check if this section is already defined, needed as some parameters // might have the same references + global $PLUGIN_HOOKS; if (isset($this->sections[$title])) { return; } @@ -131,6 +134,16 @@ public function addSection( // Keep track of parameters needing aditionnal references $references = []; + //additional parameters + foreach ($PLUGIN_HOOKS[Hooks::GET_CONTENT_TEMPLATE_PARAMETER] as $plugin => $hook_callable) { + $plugin_parameters = Plugin::doOneHook($plugin, Hooks::GET_CONTENT_TEMPLATE_PARAMETER, $fields_prefix); + if (is_array($plugin_parameters)) { + foreach ($plugin_parameters as $plugin_parameter) { + array_push($parameters, $plugin_parameter); + } + } + } + // Add a row for each parameters foreach ($parameters as $parameter) { /** @var ParameterTypeInterface $parameter */ diff --git a/src/Glpi/ContentTemplates/TemplateManager.php b/src/Glpi/ContentTemplates/TemplateManager.php index b844a6e95f9..85422ee9c6f 100644 --- a/src/Glpi/ContentTemplates/TemplateManager.php +++ b/src/Glpi/ContentTemplates/TemplateManager.php @@ -37,7 +37,9 @@ use CommonITILObject; use Glpi\Error\ErrorHandler; +use Glpi\Plugin\Hooks; use Glpi\RichText\RichText; +use Plugin; use Twig\Environment; use Twig\Error\Error; use Twig\Error\SyntaxError; @@ -107,14 +109,25 @@ public static function renderContentForCommonITIL( CommonITILObject $itil_item, string $template ): ?string { + global $PLUGIN_HOOKS; $parameters = $itil_item->getContentTemplatesParametersClassInstance(); + $parameters_value = $parameters->getValues($itil_item); + foreach ($PLUGIN_HOOKS[Hooks::GET_CONTENT_TEMPLATE_VALUE] as $plugin => $hook_callable) { + $plugin_parameters = Plugin::doOneHook($plugin, Hooks::GET_CONTENT_TEMPLATE_VALUE, ['NodeName' => $parameters->getDefaultNodeName(), 'id' => $itil_item->fields['id']]); + if (is_array($plugin_parameters)) { + foreach ($plugin_parameters as $key => $value) { + $parameters_value[$key] = $value; + } + } + } + try { $html = TemplateManager::render( $template, [ 'itemtype' => $itil_item->getType(), - $parameters->getDefaultNodeName() => $parameters->getValues($itil_item), + $parameters->getDefaultNodeName() => $parameters_value, ] ); } catch (Error $e) { diff --git a/src/Glpi/Plugin/Hooks.php b/src/Glpi/Plugin/Hooks.php index 61f03a14929..b8d29886f38 100644 --- a/src/Glpi/Plugin/Hooks.php +++ b/src/Glpi/Plugin/Hooks.php @@ -565,6 +565,20 @@ class Hooks */ public const SHOW_ITEM_STATS = 'show_item_stats'; + /** + * Register a function to display new variables in reply messages. + * The function is called with the name of actual item. + * The function is expected to return an array with parmeter. + */ + public const GET_CONTENT_TEMPLATE_PARAMETER = 'get_content_template_parameter'; + + /** + * Register a function to display new variables in reply messages. + * The function is called with type and id of the actuel item. + * The function is expected to return an array with parameters values. + */ + public const GET_CONTENT_TEMPLATE_VALUE = 'get_content_template_value'; + /** * Register a function to add additional permission restrictions for the item. * The function is called with the item as a parameter. @@ -1408,6 +1422,8 @@ public static function getItemHooks(): array self::POST_SHOW_TAB, self::POST_PREPAREADD, self::SHOW_ITEM_STATS, + self::GET_CONTENT_TEMPLATE_PARAMETER, + self::GET_CONTENT_TEMPLATE_VALUE, self::TIMELINE_ACTIONS, ]; }