From 89ce453d0d65c7513e4aa1b429d4f90a1c6d35d0 Mon Sep 17 00:00:00 2001 From: keboeoris Date: Tue, 2 Jul 2024 07:54:35 +0200 Subject: [PATCH] New hook to add custom header tags (#17263) --- src/Html.php | 13 +++++++++++++ src/Plugin/Hooks.php | 2 ++ templates/layout/parts/head.html.twig | 5 +++++ 3 files changed, 20 insertions(+) diff --git a/src/Html.php b/src/Html.php index 579fbf60a47..5238249f7fb 100644 --- a/src/Html.php +++ b/src/Html.php @@ -1304,6 +1304,19 @@ public static function includeHeader( } $tpl_vars['css_files'][] = ['path' => 'css/palettes/' . $theme . '.scss']; + // Add specific meta tags for plugins + $custom_header_tags = []; + if (isset($PLUGIN_HOOKS[Hooks::ADD_HEADER_TAG]) && count($PLUGIN_HOOKS[Hooks::ADD_HEADER_TAG])) { + foreach ($PLUGIN_HOOKS[Hooks::ADD_HEADER_TAG] as $plugin => $plugin_header_tags) { + if (!Plugin::isPluginActive($plugin)) { + continue; + } + array_push($custom_header_tags, ...$plugin_header_tags); + } + } + $tpl_vars['custom_header_tags'] = $custom_header_tags; + + $tpl_vars['js_files'][] = ['path' => 'public/lib/base.js']; $tpl_vars['js_files'][] = ['path' => 'js/webkit_fix.js']; $tpl_vars['js_files'][] = ['path' => 'js/common.js']; diff --git a/src/Plugin/Hooks.php b/src/Plugin/Hooks.php index d7a2258659f..30f8c55d467 100644 --- a/src/Plugin/Hooks.php +++ b/src/Plugin/Hooks.php @@ -43,6 +43,7 @@ class Hooks // File hooks const ADD_CSS = 'add_css'; const ADD_JAVASCRIPT = 'add_javascript'; + const ADD_HEADER_TAG = 'add_header_tag'; // Function hooks with no parameters const CHANGE_ENTITY = 'change_entity'; @@ -185,6 +186,7 @@ public static function getFunctionalHooks(): array self::UNDISCLOSED_CONFIG_VALUE, self::UNLOCK_FIELDS, self::VCARD_DATA, + self::ADD_HEADER_TAG ]; } diff --git a/templates/layout/parts/head.html.twig b/templates/layout/parts/head.html.twig index 11a273ba287..1f37cf0180b 100644 --- a/templates/layout/parts/head.html.twig +++ b/templates/layout/parts/head.html.twig @@ -48,6 +48,11 @@ {# prevent robots to index GLPI instances #} + {# Custom header tags for plugins #} + {% for header_tag in custom_header_tags %} + <{{ header_tag.tag }} {% for key, value in header_tag.properties %}{{ key }}="{{ value }}" {% endfor %}/> + {% endfor %} + {% for css_file in css_files %}